$(function () {
    let buttonGroup = [
        {
            id: 'btn_search',
            size: 'small',
            text: '查询',
            iconCls: 'icon-search',
            onClick: btn_search,
            plain: true
        },
        // {
        //     id: 'btn_add',
        //     size: 'small',
        //     text: '生成发货单',
        //     iconCls: 'icon-add',
        //     plain: true,
        //     onClick: btn_add
        // },
        {
            id: 'btn_print_bill',
            size: 'small',
            text: '打印发货单',
            iconCls: 'icon-print',
            plain: true,
            onClick: btn_print_bill
        },
        // {
        //     id: 'btn_delete',
        //     size: 'small',
        //     text: '作废发货单',
        //     iconCls: 'icon-print',
        //     plain: true,
        //     onClick: btn_delete
        // },
        {
            id: 'btn_export',
            size: 'small',
            text: '导出Excel',
            iconCls: 'icon-page_excel',
            plain: true,
            onClick: btn_export_excel
        },
        {
            id: 'btn_cancel_filter',
            size: 'small',
            text: '清除过滤',
            iconCls: 'icon-clear',
            plain: true,
            onClick: btn_cancel_filter
        },
        {
            id: 'btn_print',
            size: 'small',
            text: '打印细码单',
            iconCls: 'icon-print',
            plain: true,
            onClick: btn_print
        },
        {
            id: 'btn_grid_columns',
            size: 'small',
            text: '列',
            iconCls: 'icon-text_columns',
            plain: true,
            onClick: btn_open_column_list
        },
        // {
        //     id: 'btn_cancel_audit',
        //     size: 'small',
        //     disabled: true,
        //     text: '消审',
        //     iconCls: 'icon-exclamation',
        //     onClick: btn_cancel_audit,
        //     plain: true
        // },
        {
            id: 'btn_close', size: 'small', text: '关闭', iconCls: 'icon-no', onClick: btn_close,
            plain: true
        },
    ];
    buttonGen($('#north'), buttonGroup);
    bindEnterEvents();

    setgrid();  // 预发货网格
    setgrid_ck(); // 库存明细网格
    setgrid_fh();  // 发货明细网格
    setgrid_xmd();  // 细码单明细网格

    setcombox();  // 设置下拉

})

//设置下拉
function setcombox() {
    $.ajax({
        url: "contactCompany/listQuery",
        type: 'get',
        dataType: 'json',
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            // console.log(cdata);
            $('#client').combobox({
                data:cdata,
                limitToList:true,
                valueField:'companyName',
                textField:'companyName'
            });
            $('#client_main').combobox({
                data:cdata,
                limitToList:true,
                valueField:'companyName',
                textField:'companyName'
            });
            $('#client_detail').combobox({
                data:cdata,
                limitToList:true,
                valueField:'companyName',
                textField:'companyName'
            });
        }
    });
    $('#address').combobox({
        url:'address/listQuery',
        queryParams:{'parentId': $('#client').combobox('getValue')},
        method:'GET',
        limitToList:false,
        valueField:'location',
        textField:'location',
        onShowPanel:function(){
            // 设置新的URL和参数
            $(this).combobox('options').url = 'address/listQuery';
            $(this).combobox('options').queryParams = {parentId: $('#client').combobox('getValue')};
            // 重新加载
            $(this).combobox('reload');
        },
    })
    $('#address_bill').combobox({
        url:'address/listQuery',
        queryParams:{'parentId': $('#client_bill').combobox('getValue')},
        method:'GET',
        limitToList:false,
        valueField:'location',
        textField:'location',
        onShowPanel:function(){
            // 设置新的URL和参数
            $(this).combobox('options').url = 'address/listQuery';
            $(this).combobox('options').queryParams = {parentId: $('#client_bill').combobox('getValue')};
            // 重新加载
            $(this).combobox('reload');
        },
    })
}

//  选中事件
function onSelect(title, index) {
    function state(f) {
        if (f) {
            $('#start').datebox('disable');
            $('#end').datebox('disable');
        } else {
            $('#start').datebox('enable');
            $('#end').datebox('enable');
        }
    }

    switch (index) {
        case 0:
            if ($('#v_grid').data('kendoGrid') == undefined) {
                grid_1();  //预发货码单
            }
            state(false);
            getgriddata(0);
            $('#btn_add').linkbutton('enable');
            $('#btn_delete').linkbutton('disable');
            $('#btn_print_bill').linkbutton('disable');
            $('#btn_print').linkbutton('enable');
            setgrid();

            break;
        case 1:
            if ($('#v_grid_0').data('kendoGrid') == undefined) {
                grid_0();  // 成品发货
            }
            state(false);
            getgriddata(3);
            $('#btn_add').linkbutton('disable');
            $('#btn_delete').linkbutton('enable');
            $('#btn_print_bill').linkbutton('enable');
            $('#btn_print').linkbutton('disable');
            break;
        case 2:
            if ($('#v_grid_1').data('kendoGrid') == undefined) {
                grid_2();  // 成品入库
            }
            state(false);
            getgriddata(1);
            $('#btn_add').linkbutton('disable');
            $('#btn_delete').linkbutton('disable');
            $('#btn_print_bill').linkbutton('disable');
            $('#btn_print').linkbutton('disable');
            break;
        case 3:
            if ($('#v_grid_2').data('kendoGrid') == undefined) {
                grid_3();  //成品库存
            }
            state(true);
            getgriddata(2);
            $('#btn_add').linkbutton('disable');
            $('#btn_delete').linkbutton('disable');
            $('#btn_print_bill').linkbutton('disable');
            $('#btn_print').linkbutton('disable');
            setgrid();
            break;
        case 4:
            if ($('#v_grid_3').data('kendoGrid') == undefined) {
                grid_dcl();  //待处理
            }
            state(false);
            getgriddata(7);
            $('#btn_add').linkbutton('disable');
            $('#btn_delete').linkbutton('disable');
            $('#btn_print_bill').linkbutton('disable');
            $('#btn_print').linkbutton('disable');
            break;
        case 5:
            if ($('#v_grid_6').data('kendoGrid') == undefined) {
                grid_6();  //本厂库存
            }
            state(true);
            getgriddata(6);
            $('#btn_add').linkbutton('disable');
            $('#btn_delete').linkbutton('disable');
            $('#btn_print_bill').linkbutton('disable');
            $('#btn_print').linkbutton('disable');
            setgrid();
            break;

        case 6:
            if ($('#v_grid_4').data('kendoGrid') == undefined) {
                grid_4();  // 预发货码单明细
            }
            state(false);
            getgriddata(4);
            $('#btn_add').linkbutton('enable');
            $('#btn_delete').linkbutton('disable');
            $('#btn_print_bill').linkbutton('disable');
            $('#btn_print').linkbutton('enable');
            setgrid();

            break;

        case 7:
            if ($('#v_grid_5').data('kendoGrid') == undefined) {
                grid_5();  // 成品发货明细
            }
            state(false);
            getgriddata(5);
            $('#btn_add').linkbutton('disable');
            $('#btn_delete').linkbutton('enable');
            $('#btn_print_bill').linkbutton('enable');
            $('#btn_print').linkbutton('disable');
            break;
    }
}

//报表数据源
function getgriddata(val) {
    var kGrid = getSelectedGrid();
    $.messager.progress({title: '', msg: '请稍等...', interval: 5000});
    $.ajax({
        url: "customize/callProc",
        type: 'post',
        data: JSON.stringify(['p_dye_delivery_report',$('#start').datebox('getValue'),$('#end').datebox('getValue'),val]),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            let  data=cdata.data;
            console.log(data);
            kGrid.dataSource.data(data);

        }, complete: function () {
            $.messager.progress('close');
        }

    })
}

/**
 * 2021年8月11日 11:06:32 chanchaw
 * 成品管理 - 第一个标签页 - 预发货细码单
 */
function grid_1() {
    let SUFFIX = "_a";
    let billcode = new kendo.data.DataSource({data: []});
    let datafh = new kendo.data.DataSource({data: []});
    let product_name = new kendo.data.DataSource({data: []});
    let specification = new kendo.data.DataSource({data: []});
    let color = new kendo.data.DataSource({data: []});
    let color_no = new kendo.data.DataSource({data: []});
    let memo = new kendo.data.DataSource({data: []});
    let address = new kendo.data.DataSource({data: []});
    let client = new kendo.data.DataSource({data: []});
    let manager = new kendo.data.DataSource({data: []});
    let carnumber = new kendo.data.DataSource({data: []});
    let company_name = new kendo.data.DataSource({data: []});
    let order_code = new kendo.data.DataSource({data: []});
    let remark = new kendo.data.DataSource({data: []});

    let dataSource = new kendo.data.DataSource({
        schema: {
            model: {
                fields: {
                    ps: {type: "number"},
                    qty: {type: "number"},
                    price: {type: "number"},
                    money: {type: "number"},
                }
            }
        },
        aggregate: [
            {field: "ps", aggregate: "sum"},
            {field: "qty", aggregate: "sum"},
            {field: "money", aggregate: "sum"},
        ],
        change: function (e) {
            // let data = this.data();
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            let data = query.filter(filtrer).data;

            client.data(unique(data, 'client'));
            billcode.data(unique(data, 'billcode'));
            product_name.data(unique(data, 'product_name'));
            specification.data(unique(data, 'specification'));
            color.data(unique(data, 'color'));
            color_no.data(unique(data, 'color_no'));
            memo.data(unique(data, 'memo'));
            manager.data(unique(data, 'manager'));
            carnumber.data(unique(data, 'carnumber'));
            address.data(unique(data, 'address'));
            company_name.data(unique(data, 'company_name'));
            order_code.data(unique(data, 'order_code'));
            remark.data(unique(data, 'remark'));

        },
        pageSize: 200,
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('disable')
                }
            })
        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('enable')
                }
            })
        }
    });
    let columns = [
        {field: "no", title: "#", filterable: false, template: "<span class='row_number'></span>", width: 40},
        {
            field: "id",
            title: '编号',
            width: 93,
            hidden: true,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
        },
        {
            field: "client",
            title: '码单客户',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        },
        {
            field: "billcode",
            title: '细码单号',
            width: 93,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: billcode}
        },
        {
            field: "datafh",
            title: '扫码日期',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: datafh}
        },
        {
            field: "order_code",
            title: '订单号',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: order_code}
        },
        {
            field: "company_name",
            title: '计划客户',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: company_name}
        },
        // {
        //     field: "clientAlias",
        //     title: '客户单号',
        //     width: 85,
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        // },
        {
            field: "product_name",
            title: '品名',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: product_name}
        },
        {
            field: "specification",
            title: '规格',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: specification}
        },
        {
            field: "color",
            title: '颜色',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color}
        },
        {
            field: "ps",
            title: '匹数',
            width: 93,
            template: item => item['ps'] ? parseFloat(item['ps']).toFixed(0) : '',
            footerTemplate: '#=kendo.format("{0:n0}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "qty",
            title: '重量',
            width: 93,
            template: item => item['qty'] ? parseFloat(item['qty']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        // {
        //     field: "price",
        //     title: '单价',
        //     width: 93,
        //     template: item => item['price'] ? parseFloat(item['price']).toFixed(1) : '',
        //     // footerTemplate: '#=kendo.format("{0:n0}",sum)#',
        //     footerAttributes: {'style': 'text-align:right;'},
        //     attributes: {'class': 'kendo-custum-number'},
        //     headerAttributes: {'style': 'text-align:center;'},
        //     filterable: false
        // },
        {
            field: "money",
            title: '金额',
            width: 93,
            template: item => item['money'] ? parseFloat(item['money']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        // {
        //     field: "manager",
        //     title: '经手人',
        //     width: 80,
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: manager}
        // },
        // {
        //     field: "carnumber",
        //     title: '车牌号',
        //     width: 80,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: carnumber}
        // },
        // {
        //     field: "address",
        //     title: '收货单位',
        //     width: 120,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: address}
        // },
        // {
        //     field: "hideClient",
        //     title: '打印客户',
        //     width: 100,
        //     template: item => item['hideClient'] ? '是' : '否',
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: false
        // },
        {
            field: "showPrice",
            title: '打印单价',
            width: 100,
            template: item => item['showPrice'] ? '是' : '否',
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: false
        },
        // {
        //     field: "memo",
        //     title: '发货备注',
        //     width: 150,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: memo}
        // },
        // {
        //     field: "remark",
        //     title: '厂内备注',
        //     width: 150,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: remark}
        // },


    ];
    let grid = $("#v_grid").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: {
            extra: false
        },
        dataSource: dataSource,
        columnMenu: false,
        excel: {
            fileName: "预发货码单.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        height: '99%',
        pageable: {
            pageSize: 200
        },
        reorderable: true,
        dataBound: function () {
            let rows = this.items();
            let kGrid = $('#v_grid').data('kendoGrid');
            $(rows).each(function () {
                let index = $(this).index() + 1;
                let rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
                let dataItem = kGrid.dataItem($(this));
                if (dataItem['is_audit'] != undefined && !dataItem['is_audit']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
                if (dataItem['state'] != undefined && !dataItem['state']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
            });
        },
        columnHide: function (e) {
            //列隐藏事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
        },
        columnShow: function (e) {
            //列显示事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, false, null, SUFFIX);
        },
        columnResize: function (e) {
            //  列伸缩事件
            let field = e.column.field;
            let newWidth = e.newWidth;
            if (newWidth < 20) {
                columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
            } else {
                columnResizeEvent($('body').data('menu_id'), field, newWidth, null, null, SUFFIX);
            }
        },
        columnReorder: function (e) {
            //  列拖动事件
            let newColumns = JSON.parse(JSON.stringify(e.sender.columns))
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);
            let menuId = $('body').data('menu_id');
            let col = []
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        serialNum: i,
                        sysMenuId: menuId,
                        field: newColumns[i]['field'] + SUFFIX
                    });
            }
            $.ajax({
                url: 'sysUserTableConfig/modify/reorder',
                contentType: 'application/json',
                data: JSON.stringify(col),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                }
            })
        },
    });
    let grid01 = $('#v_grid').data('kendoGrid');
    loadOptions(grid01, columns, SUFFIX, $('body').data('menu_id'));
    grid01.setOptions({
        columns: columns
    });
    grid.on('dblclick', 'tr', function (e) {
        setgrid_fh();
        //  修改单据
        let kGrid = $("#v_grid").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        open_fhdetail(dataItem);
    })
    grid.on('click', 'tr', function (e) {
        let kGrid = $("#v_grid").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        if (dataItem['is_audit']) {
            $('#btn_cancel_audit').linkbutton('enable')
        } else {
            $('#btn_cancel_audit').linkbutton('disable')
        }
    })
    grid.on('contextmenu', 'tr', function (e) {
        e.preventDefault();
        let kGrid = $('#v_grid').data('kendoGrid');
        var selectedRows = kGrid.select();
        let div = $(`<div class="easyui-menu_01">
                         <div data-options="name:'设置发货',iconCls:'icon-ok'">生成发货单</div>
                         <div data-options="name:'作废',iconCls:'icon-cancel'">作废细码单</div>
                     </div>`);
        $('body').append(div);
        div.menu({
            onClick: function (item) {
                let name = item.text;
                switch (name) {
                    case '生成发货单':
                        $("#address").combobox('enable');
                        btn_add();
                        // let selectedDataItems = [];
                        // let yfh_data=[];
                        // for (let i = 0; i < selectedRows.length; i++) {
                        //     let dataItem = kGrid.dataItem(selectedRows[i]);
                        //     selectedDataItems.push(dataItem.billcode);
                        //     if (!dataItem.client){
                        //         let Obj= {"product_name":dataItem.product_name,"material_specification":dataItem.material_specification,"client":dataItem.client,
                        //             "ps":dataItem.ps,"qty":dataItem.qty,"billcode":dataItem.billcode};
                        //         yfh_data.push(Obj);
                        //     }else{
                        //         $.messager.alert({title: '提示', msg: "已设置客户不允许选择批量设置！"});
                        //         return;
                        //     }
                        // }
                        // console.log(selectedDataItems);
                        // if(yfh_data.length>0){
                        //     $('#fh_main').dialog('open');
                        //     $("#hideClientB").checkbox('check').checked;
                        //     $("#showPriceB").checkbox('clear').checked;
                        // }else{
                        //     $.messager.alert({title: '提示', msg: "未选择数据！！！"});
                        // }
                        break;
                    case '作废细码单':
                        if(selectedRows.length>1){
                            $.messager.alert({title: '提示', msg: "作废不允许多选！！！"});
                            return;
                        }
                        if(selectedRows.length>0){
                            $.messager.confirm('确认', '确定作废当前选中细码单吗？不可恢复！', function (r) {
                                if (r) {
                                    $.ajax({
                                        url: "cpBillfh/setVoid",
                                        type: 'post',
                                        data: JSON.stringify({"id":kGrid.dataItem(selectedRows[0]).id}),
                                        contentType: "application/json;charset=UTF-8",
                                        success: function (cdata) {
                                            // let  data=cdata.data;
                                            btn_search();
                                            $.messager.show({title: '提示', msg: "作废发货完成！！！"});
                                        }
                                    });
                                }
                            })

                        }else{
                            $.messager.alert({title: '提示', msg: "未选择数据！！！"});
                        }
                        break;
                }
            },
        });
        div.menu('show', {
            left: e.pageX,
            top: e.pageY
        })
    });
}

/**
 * 2021年8月11日 11:06:32 chanchaw
 * 成品管理 - 第一个标签页 - 发货单序时表
 */
function grid_0() {
    let SUFFIX = "_a";
    let billcode = new kendo.data.DataSource({data: []});
    let datafh = new kendo.data.DataSource({data: []});
    let product_name = new kendo.data.DataSource({data: []});
    let specification = new kendo.data.DataSource({data: []});
    let color = new kendo.data.DataSource({data: []});
    let color_no = new kendo.data.DataSource({data: []});
    let memo = new kendo.data.DataSource({data: []});
    let address = new kendo.data.DataSource({data: []});
    let client = new kendo.data.DataSource({data: []});
    let manager = new kendo.data.DataSource({data: []});
    let carnumber = new kendo.data.DataSource({data: []});
    let company_name = new kendo.data.DataSource({data: []});
    let order_code = new kendo.data.DataSource({data: []});
    let remark = new kendo.data.DataSource({data: []});

    let dataSource = new kendo.data.DataSource({
        schema: {
            model: {
                fields: {
                    ps: {type: "number"},
                    qty: {type: "number"},
                    // price: {type: "number"},
                    money: {type: "number"},
                }
            }
        },
        aggregate: [
            {field: "ps", aggregate: "sum"},
            {field: "qty", aggregate: "sum"},
            {field: "money", aggregate: "sum"},
        ],
        change: function (e) {
            // let data = this.data();
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            let data = query.filter(filtrer).data;

            client.data(unique(data, 'client'));
            billcode.data(unique(data, 'billcode'));
            product_name.data(unique(data, 'product_name'));
            specification.data(unique(data, 'specification'));
            color.data(unique(data, 'color'));
            color_no.data(unique(data, 'color_no'));
            memo.data(unique(data, 'memo'));
            manager.data(unique(data, 'manager'));
            carnumber.data(unique(data, 'carnumber'));
            address.data(unique(data, 'carnumber'));
            company_name.data(unique(data, 'company_name'));
            order_code.data(unique(data, 'order_code'));
            remark.data(unique(data, 'remark'));

        },
        pageSize: 200,
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('disable')
                }
            })
        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('enable')
                }
            })
        }
    });
    let columns = [
        {field: "no", title: "#", filterable: false, template: "<span class='row_number'></span>", width: 40},
        {
            field: "id",
            title: '编号',
            width: 93,
            hidden: true,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
        },
        {
            field: "billcode",
            title: '发货单号',
            width: 93,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: billcode}
        },
        {
            field: "datafh",
            title: '发货日期',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: datafh}
        },
        // {
        //     field: "order_code",
        //     title: '订单号',
        //     width: 85,
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: order_code}
        // },
        {
            field: "client",
            title: '客户',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        },
        // {
        //     field: "client",
        //     title: '客户单号',
        //     width: 85,
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        // },
        // {
        //     field: "product_name",
        //     title: '品名',
        //     width: 85,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: product_name}
        // },
        // {
        //     field: "specification",
        //     title: '规格',
        //     width: 85,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: specification}
        // },
        // {
        //     field: "color",
        //     title: '颜色',
        //     width: 85,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: color}
        // },
        {
            field: "ps",
            title: '总匹数',
            width: 93,
            template: item => item['ps'] ? parseFloat(item['ps']).toFixed(0) : '',
            footerTemplate: '#=kendo.format("{0:n0}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "qty",
            title: '总重量',
            width: 93,
            template: item => item['qty'] ? parseFloat(item['qty']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        // {
        //     field: "price",
        //     title: '单价',
        //     width: 93,
        //     template: item => item['price'] ? parseFloat(item['price']).toFixed(1) : '',
        //     // footerTemplate: '#=kendo.format("{0:n0}",sum)#',
        //     footerAttributes: {'style': 'text-align:right;'},
        //     attributes: {'class': 'kendo-custum-number'},
        //     headerAttributes: {'style': 'text-align:center;'},
        //     filterable: false
        // },
        {
            field: "money",
            title: '总金额',
            width: 93,
            template: item => item['money'] ? parseFloat(item['money']).toFixed(2) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "manager",
            title: '经手人',
            width: 80,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: manager}
        },
        {
            field: "carnumber",
            title: '车牌号',
            width: 80,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: carnumber}
        },
        {
            field: "address",
            title: '收货单位',
            width: 120,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: address}
        },
        // {
        //     field: "hideClient",
        //     title: '打印客户',
        //     width: 100,
        //     template: item => item['hideClient'] ? '是' : '否',
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: false
        // },
        // {
        //     field: "showPrice",
        //     title: '打印单价',
        //     width: 100,
        //     template: item => item['showPrice'] ? '是' : '否',
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: false
        // },
        {
            field: "memo",
            title: '发货备注',
            width: 150,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: memo}
        },
        {
            field: "remark",
            title: '厂内备注',
            width: 150,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: remark}
        },


    ];
    let grid = $("#v_grid_0").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: {
            extra: false
        },
        dataSource: dataSource,
        columnMenu: false,
        excel: {
            fileName: "成品发货序时表.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        height: '99%',
        pageable: {
            pageSize: 200
        },
        reorderable: true,
        dataBound: function () {
            let rows = this.items();
            let kGrid = $('#v_grid_0').data('kendoGrid');
            $(rows).each(function () {
                let index = $(this).index() + 1;
                let rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
                let dataItem = kGrid.dataItem($(this));
                if (dataItem['is_audit'] != undefined && !dataItem['is_audit']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
                if (dataItem['state'] != undefined && !dataItem['state']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
            });
        },
        columnHide: function (e) {
            //列隐藏事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
        },
        columnShow: function (e) {
            //列显示事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, false, null, SUFFIX);
        },
        columnResize: function (e) {
            //  列伸缩事件
            let field = e.column.field;
            let newWidth = e.newWidth;
            if (newWidth < 20) {
                columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
            } else {
                columnResizeEvent($('body').data('menu_id'), field, newWidth, null, null, SUFFIX);
            }
        },
        columnReorder: function (e) {
            //  列拖动事件
            let newColumns = JSON.parse(JSON.stringify(e.sender.columns))
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);
            let menuId = $('body').data('menu_id');
            let col = []
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        serialNum: i,
                        sysMenuId: menuId,
                        field: newColumns[i]['field'] + SUFFIX
                    });
            }
            $.ajax({
                url: 'sysUserTableConfig/modify/reorder',
                contentType: 'application/json',
                data: JSON.stringify(col),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                }
            })
        },
    });
    let grid01 = $('#v_grid_0').data('kendoGrid');
    loadOptions(grid01, columns, SUFFIX, $('body').data('menu_id'));
    grid01.setOptions({
        columns: columns
    });
    grid.on('dblclick', 'tr', function (e) {
        setgrid_fh();
        //  修改单据
        let kGrid = $("#v_grid_0").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        open_fhdetail(dataItem);
    })
    grid.on('click', 'tr', function (e) {
        let kGrid = $("#v_grid_0").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        if (dataItem['is_audit']) {
            $('#btn_cancel_audit').linkbutton('enable')
        } else {
            $('#btn_cancel_audit').linkbutton('disable')
        }
    })
    grid.on('contextmenu', 'tr', function (e) {
        // e.preventDefault();
        // let kGrid = $('#v_grid_0').data('kendoGrid');
        // var selectedRows = kGrid.select();
        // let div = $(`<div class="easyui-menu_00">
        //                  <div data-options="name:'作废',iconCls:'icon-cancel'">作废发货单</div>
        //              </div>`);
        // $('body').append(div);
        // div.menu({
        e.preventDefault();
        let kGrid = $("#v_grid_0").data("kendoGrid");
        kGrid.clearSelection();
        kGrid.select(this);
        let row = kGrid.select();
        let dataItem = kGrid.dataItem(row);
        let selectedRows=[];
        selectedRows.push(dataItem);
        let div = "<div id = 'easyui-menu_00'>"
            + "<div data-options=\"iconCls:'icon-cancel'\">作废发货单</div>"
            + "</div>";
        if ($('#easyui-menu_00').length <= 0)
            $('body').append(div);
        $('#easyui-menu_00').menu({
            onClick: function (item) {
                let name = item.text;
                switch (name) {
                    case '作废发货单':
                        if(selectedRows.length>1){
                            $.messager.alert({title: '提示', msg: "作废不允许多选！！！"});
                            return;
                        }
                        if(selectedRows.length>0){
                            btn_delete();
                        }else{
                            $.messager.alert({title: '提示', msg: "未选择数据！！！"});
                        }
                        break;
                }
            },
        });
        $('#easyui-menu_00').menu('show', {
            left: e.pageX,
            top: e.pageY
        })
    });
}

/**
 * 2021年8月11日 11:06:32 chanchaw
 * 成品管理 - 第二个标签页 - 色布入库
 */
function grid_2() {
    let SUFFIX = "_b";
    let plan_code = new kendo.data.DataSource({data: []});
    let order_code = new kendo.data.DataSource({data: []});
    let product_name = new kendo.data.DataSource({data: []});
    let material_specification = new kendo.data.DataSource({data: []});
    let color_no = new kendo.data.DataSource({data: []});
    let color = new kendo.data.DataSource({data: []});
    let company_name = new kendo.data.DataSource({data: []});
    let client = new kendo.data.DataSource({data: []});
    let B_Class = new kendo.data.DataSource({data: []});
    let B_JTH= new kendo.data.DataSource({data: []});
    let b_barcode = new kendo.data.DataSource({data: []});
    let dataSource = new kendo.data.DataSource({
        // transport: {
        // read: {
        //     url: "dyeFabricDelivery/report/dyeFabric/input",
        //     dataType: "json",
        //     type: "GET",
        //     data: {
        //         start: $('#start').datebox('getValue'),
        //         end: $('#end').datebox('getValue'),
        //         clientName: $('#contactCompanyId').combobox('getValue'),
        //         // textField: $('#column').combobox('getValue'),
        //         // valueField: $('#value').textbox('getValue'),
        //     }
        // }
        // },
        schema: {
            model: {
                fields: {
                    ps: {type: "number"},
                    qty: {type: "number"},
                    meter: {type: "number"},
                }
            }
        },
        aggregate: [
            {field: "ps", aggregate: "sum"},
            {field: "qty", aggregate: "sum"},
            {field: "meter", aggregate: "sum"},
        ],
        change: function (e) {
            // let data = this.data();
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            let data = query.filter(filtrer).data;

            plan_code.data(unique(data, 'plan_code'));
            order_code.data(unique(data, 'order_code'));
            product_name.data(unique(data, 'product_name'));
            material_specification.data(unique(data, 'material_specification'));
            color_no.data(unique(data, 'color_no'));
            color.data(unique(data, 'color'));
            company_name.data(unique(data, 'company_name'));
            client.data(unique(data, 'client'));
            B_Class.data(unique(data, 'B_Class'));
            B_JTH.data(unique(data, 'B_JTH'));
            b_barcode.data(unique(data, 'b_barcode'));

            $('#btn_cancel_audit').linkbutton('disable')
        },
        pageSize: 200,
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('disable')
                }
            })

        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('enable')
                }
            })

        }
    });
    let columns = [
        {field: "no", title: "#", filterable: false, template: "<span class='row_number'></span>", width: 40},
        {
            field: "id",
            title: '编号',
            width: 93,
            hidden: true,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
        },
        {
            field: "plan_code",
            title: '卡片号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: plan_code}
        },
        {
            field: "b_barcode",
            title: '二维码编号',
            width: 100,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: b_barcode}
        },
        {
            field: "product_name",
            title: '品名',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: product_name}
        },
        {
            field: "material_specification",
            title: '规格',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: material_specification}
        },
        {
            field: "color",
            title: '颜色',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color}
        },
        {
            field: "color_no",
            title: '色号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color_no}
        },
        {
            field: "B_JTH",
            title: '机台号',
            width: 80,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: B_JTH}
        },

        {
            field: "ps",
            title: '匹数',
            width: 93,
            template: item => item['ps'] ? parseFloat(item['ps']).toFixed(0) : '',
            footerTemplate: '#=kendo.format("{0:n0}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "qty",
            title: '重量',
            width: 93,
            template: item => item['qty'] ? parseFloat(item['qty']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "meter",
            title: '米数',
            width: 93,
            template: item => item['meter'] ? parseFloat(item['meter']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "order_code",
            title: '订单号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: order_code}
        },
        {
            field: "company_name",
            title: '客户',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: company_name}
        },
        {
            field: "client",
            title: '客户单号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        },
        {
            field: "B_DTRK",
            title: '入库时间',
            width: 120,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            filterable: false
        },

    ];
    let grid = $("#v_grid_1").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: {
            extra: false
        },
        dataSource: dataSource,
        columnMenu: false,
        excel: {
            fileName: "成品入库序时表.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        height: '99%',
        pageable: {
            pageSize: 200
        },
        reorderable: true,
        dataBound: function () {
            let rows = this.items();
            let kGrid = $('#v_grid_1').data('kendoGrid');
            $(rows).each(function () {
                let index = $(this).index() + 1;
                let rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
                let dataItem = kGrid.dataItem($(this));
                if (dataItem['is_audit'] != undefined && !dataItem['is_audit']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
            });
        },
        columnHide: function (e) {
            //列隐藏事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
        },
        columnShow: function (e) {
            //列显示事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, false, null, SUFFIX);
        },
        columnResize: function (e) {
            //  列伸缩事件
            let field = e.column.field;
            let newWidth = e.newWidth;
            if (newWidth < 20) {
                columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
            } else {
                columnResizeEvent($('body').data('menu_id'), field, newWidth, null, null, SUFFIX);
            }
        },
        columnReorder: function (e) {
            //  列拖动事件
            let newColumns = JSON.parse(JSON.stringify(e.sender.columns))
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);
            let menuId = $('body').data('menu_id');
            let col = []
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        serialNum: i,
                        sysMenuId: menuId,
                        field: newColumns[i]['field'] + SUFFIX
                    });
            }
            $.ajax({
                url: 'sysUserTableConfig/modify/reorder',
                contentType: 'application/json',
                data: JSON.stringify(col),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                }
            })
        },
    });
    let grid01 = $('#v_grid_1').data('kendoGrid');
    loadOptions(grid01, columns, SUFFIX, $('body').data('menu_id'));
    grid01.setOptions({
        columns: columns
    });
    grid.on('dblclick', 'tr', function (e) {
        //  修改单据
    })
    grid.on('click', 'tr', function (e) {
        let kGrid = $("#v_grid_1").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        if (dataItem['is_audit']) {
            $('#btn_cancel_audit').linkbutton('enable')
        } else {
            $('#btn_cancel_audit').linkbutton('disable')
        }
    })
}

/**
 * 2021年8月11日 11:06:32 chanchaw
 * 成品管理 - 第三个标签页 - 色布库存
 */

function grid_3() {
    let SUFFIX = "_b";
    let plan_code = new kendo.data.DataSource({data: []});
    let order_code = new kendo.data.DataSource({data: []});
    let product_name = new kendo.data.DataSource({data: []});
    let material_specification = new kendo.data.DataSource({data: []});
    let color_no = new kendo.data.DataSource({data: []});
    let color = new kendo.data.DataSource({data: []});
    let B_Class = new kendo.data.DataSource({data: []});
    let B_JTH= new kendo.data.DataSource({data: []});
    let b_barcode = new kendo.data.DataSource({data: []});
    let company_name = new kendo.data.DataSource({data: []});
    let client = new kendo.data.DataSource({data: []});
    let dataSource = new kendo.data.DataSource({
        schema: {
            model: {
                fields: {
                    ps: {type: "number"},
                    qty: {type: "number"},
                    meter: {type: "number"},
                }
            }
        },
        aggregate: [
            {field: "ps", aggregate: "sum"},
            {field: "qty", aggregate: "sum"},
            {field: "meter", aggregate: "sum"},
        ],
        change: function (e) {
            // let data = this.data();
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            let data = query.filter(filtrer).data;

            plan_code.data(unique(data, 'plan_code'));
            order_code.data(unique(data, 'order_code'));
            product_name.data(unique(data, 'product_name'));
            material_specification.data(unique(data, 'material_specification'));
            color_no.data(unique(data, 'color_no'));
            color.data(unique(data, 'color'));
            B_Class.data(unique(data, 'B_Class'));
            B_JTH.data(unique(data, 'B_JTH'));
            b_barcode.data(unique(data, 'b_barcode'));
            company_name.data(unique(data, 'company_name'));
            client.data(unique(data, 'client'));

            $('#btn_cancel_audit').linkbutton('disable')
        },
        pageSize: 200,
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('disable')
                }
            })

        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('enable')
                }
            })

        }
    });
    let columns = [
        {field: "no", title: "#", filterable: false, template: "<span class='row_number'></span>", width: 40},
        {
            field: "id",
            title: '编号',
            width: 93,
            hidden: true,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
        },
        {
            field: "plan_code",
            title: '卡片号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: plan_code}
        },
        {
            field: "b_barcode",
            title: '二维码编号',
            width: 100,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: b_barcode}
        },
        {
            field: "product_name",
            title: '品名',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: product_name}
        },
        {
            field: "material_specification",
            title: '规格',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: material_specification}
        },
        {
            field: "color",
            title: '颜色',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color}
        },
        {
            field: "color_no",
            title: '色号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color_no}
        },
        {
            field: "B_JTH",
            title: '机台号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: B_JTH}
        },

        {
            field: "ps",
            title: '匹数',
            width: 93,
            template: item => item['ps'] ? parseFloat(item['ps']).toFixed(0) : '',
            footerTemplate: '#=kendo.format("{0:n0}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "qty",
            title: '重量',
            width: 93,
            template: item => item['qty'] ? parseFloat(item['qty']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "meter",
            title: '米数',
            width: 93,
            template: item => item['meter'] ? parseFloat(item['meter']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "order_code",
            title: '订单号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: order_code}
        },
        {
            field: "company_name",
            title: '客户',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: company_name}
        },
        {
            field: "client",
            title: '客户单号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        },
        {
            field: "B_DTRK",
            title: '入库时间',
            width: 120,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            filterable: false
        },

    ];
    let grid = $("#v_grid_2").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: {
            extra: false
        },
        dataSource: dataSource,
        columnMenu: false,
        excel: {
            fileName: "成品库存序时表.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        height: '99%',
        pageable: {
            pageSize: 200
        },
        reorderable: true,
        dataBound: function () {
            let rows = this.items();
            let kGrid = $('#v_grid_2').data('kendoGrid');
            $(rows).each(function () {
                let index = $(this).index() + 1;
                let rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
                let dataItem = kGrid.dataItem($(this));
                if (dataItem['is_audit'] != undefined && !dataItem['is_audit']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
            });
        },
        columnHide: function (e) {
            //列隐藏事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
        },
        columnShow: function (e) {
            //列显示事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, false, null, SUFFIX);
        },
        columnResize: function (e) {
            //  列伸缩事件
            let field = e.column.field;
            let newWidth = e.newWidth;
            if (newWidth < 20) {
                columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
            } else {
                columnResizeEvent($('body').data('menu_id'), field, newWidth, null, null, SUFFIX);
            }
        },
        columnReorder: function (e) {
            //  列拖动事件
            let newColumns = JSON.parse(JSON.stringify(e.sender.columns))
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);
            let menuId = $('body').data('menu_id');
            let col = []
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        serialNum: i,
                        sysMenuId: menuId,
                        field: newColumns[i]['field'] + SUFFIX
                    });
            }
            $.ajax({
                url: 'sysUserTableConfig/modify/reorder',
                contentType: 'application/json',
                data: JSON.stringify(col),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                }
            })
        },
    });
    let grid01 = $('#v_grid_2').data('kendoGrid');
    loadOptions(grid01, columns, SUFFIX, $('body').data('menu_id'));
    grid01.setOptions({
        columns: columns
    });
    grid.on('dblclick', 'tr', function (e) {
        //  修改单据
        let kGrid = $("#v_grid_2").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        $('#ck_detail').dialog('open');
        getckdetail(0,dataItem.b_barcode)


    });
    grid.on('click', 'tr', function (e) {
        let kGrid = $("#v_grid_2").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        if (dataItem['is_audit']) {
            $('#btn_cancel_audit').linkbutton('enable')
        } else {
            $('#btn_cancel_audit').linkbutton('disable')
        }
    });
    grid.on('contextmenu', 'tr', function (e) {
        e.preventDefault();
        let kGrid = $('#v_grid_2').data('kendoGrid');
        var selectedRows = kGrid.select();
        let div = $(`<div class="easyui-menu">
                         <div data-options="name:'生成预发货码单',iconCls:'icon-ok'">生成预发货码单</div>
                         <div data-options="name:'转本厂',iconCls:'icon-ok'">转本厂</div>
                     </div>`);
        $('body').append(div);
        div.menu({
            onClick: function (item) {
                let name = item.text;
                switch (name) {
                    case '生成预发货码单':
                        let selectedDataItems = [];
                        let yfh_data=[];
                        for (let i = 0; i < selectedRows.length; i++) {
                            let dataItem = kGrid.dataItem(selectedRows[i]);
                            selectedDataItems.push(dataItem.b_barcode);
                            $('#client').combobox('setValue', dataItem.company_name);
                            let Obj= {
                                "product_name":dataItem.product_name,
                                "order_code":dataItem.order_code,
                                "material_specification":dataItem.material_specification,
                                "color":dataItem.color,
                                "ps":dataItem.ps,"qty":dataItem.qty,
                                "b_barcode":dataItem.b_barcode
                            };
                            yfh_data.push(Obj);
                        }
                        console.log(selectedDataItems);
                        if(yfh_data.length>0){
                            $('#client').combobox('readonly', false);
                            $('#yfh_win').dialog('open');
                            $("#hideClientA").checkbox('check').checked;
                            $("#address").combobox('disable');
                            $('#yfh_dg').datagrid('clearSelections');
                            $('#yfh_dg').datagrid('loadData', yfh_data);
                        }else{
                            $.messager.alert({title: '提示', msg: "未选择数据！！！"});
                        }
                        break;
                    case '转本厂':
                        $.messager.confirm('确认', '确定转为本厂库存吗？', function (r) {
                            if (r) {
                                let rowdata = [];
                                for (let i = 0; i < selectedRows.length; i++) {
                                    let dataItem = kGrid.dataItem(selectedRows[i]);
                                    let Obj= {
                                        "bBarcode":dataItem.b_barcode,
                                        "convertBc":1,
                                        "bDTRK":dataItem.B_DTRK
                                    };
                                    rowdata.push(Obj);
                                }
                                $.ajax({
                                    url: 'gjrkbillCp/updateByConvertBc',
                                    contentType: 'application/json',
                                    data: JSON.stringify(rowdata),
                                    type: 'post',
                                    dataType: 'json',
                                    success: function (data) {
                                        console.log(data);
                                        btn_search();
                                    }
                                });
                            }
                        });
                }
            },
        });
        div.menu('show', {
            left: e.pageX,
            top: e.pageY
        })
    });
}


/**
 * 2025年5月29日
 * 本厂库存
 */

function grid_6() {
    let SUFFIX = "_6b";
    let plan_code = new kendo.data.DataSource({data: []});
    let order_code = new kendo.data.DataSource({data: []});
    let product_name = new kendo.data.DataSource({data: []});
    let material_specification = new kendo.data.DataSource({data: []});
    let color_no = new kendo.data.DataSource({data: []});
    let color = new kendo.data.DataSource({data: []});
    let B_Class = new kendo.data.DataSource({data: []});
    let B_JTH= new kendo.data.DataSource({data: []});
    let b_barcode = new kendo.data.DataSource({data: []});
    let company_name = new kendo.data.DataSource({data: []});
    let client = new kendo.data.DataSource({data: []});
    let dataSource = new kendo.data.DataSource({
        schema: {
            model: {
                fields: {
                    ps: {type: "number"},
                    qty: {type: "number"},
                    meter: {type: "number"},
                }
            }
        },
        aggregate: [
            {field: "ps", aggregate: "sum"},
            {field: "qty", aggregate: "sum"},
            {field: "meter", aggregate: "sum"},
        ],
        change: function (e) {
            // let data = this.data();
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            let data = query.filter(filtrer).data;

            plan_code.data(unique(data, 'plan_code'));
            order_code.data(unique(data, 'order_code'));
            product_name.data(unique(data, 'product_name'));
            material_specification.data(unique(data, 'material_specification'));
            color_no.data(unique(data, 'color_no'));
            color.data(unique(data, 'color'));
            B_Class.data(unique(data, 'B_Class'));
            B_JTH.data(unique(data, 'B_JTH'));
            b_barcode.data(unique(data, 'b_barcode'));
            company_name.data(unique(data, 'company_name'));
            client.data(unique(data, 'client'));

            $('#btn_cancel_audit').linkbutton('disable')
        },
        pageSize: 200,
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('disable')
                }
            })

        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('enable')
                }
            })

        }
    });
    let columns = [
        {field: "no", title: "#", filterable: false, template: "<span class='row_number'></span>", width: 40},
        {
            field: "id",
            title: '编号',
            width: 93,
            hidden: true,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
        },
        {
            field: "plan_code",
            title: '卡片号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: plan_code}
        },
        {
            field: "b_barcode",
            title: '二维码编号',
            width: 100,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: b_barcode}
        },
        {
            field: "product_name",
            title: '品名',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: product_name}
        },
        {
            field: "material_specification",
            title: '规格',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: material_specification}
        },
        {
            field: "color",
            title: '颜色',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color}
        },
        {
            field: "color_no",
            title: '色号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color_no}
        },
        {
            field: "B_JTH",
            title: '机台号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: B_JTH}
        },

        {
            field: "ps",
            title: '匹数',
            width: 93,
            template: item => item['ps'] ? parseFloat(item['ps']).toFixed(0) : '',
            footerTemplate: '#=kendo.format("{0:n0}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "qty",
            title: '重量',
            width: 93,
            template: item => item['qty'] ? parseFloat(item['qty']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "meter",
            title: '米数',
            width: 93,
            template: item => item['meter'] ? parseFloat(item['meter']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },

        {
            field: "order_code",
            title: '订单号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: order_code}
        },
        {
            field: "company_name",
            title: '客户',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: company_name}
        },
        {
            field: "client",
            title: '客户单号',
            width: 93,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        },
        {
            field: "B_DTRK",
            title: '入库时间',
            width: 120,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;text-align:center;'},
            filterable: false
        },

    ];
    let grid = $("#v_grid_6").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: {
            extra: false
        },
        dataSource: dataSource,
        columnMenu: false,
        excel: {
            fileName: "本厂库存序时表.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        height: '99%',
        pageable: {
            pageSize: 200
        },
        reorderable: true,
        dataBound: function () {
            let rows = this.items();
            let kGrid = $('#v_grid_6').data('kendoGrid');
            $(rows).each(function () {
                let index = $(this).index() + 1;
                let rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
                let dataItem = kGrid.dataItem($(this));
                if (dataItem['is_audit'] != undefined && !dataItem['is_audit']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
            });
        },
        columnHide: function (e) {
            //列隐藏事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
        },
        columnShow: function (e) {
            //列显示事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, false, null, SUFFIX);
        },
        columnResize: function (e) {
            //  列伸缩事件
            let field = e.column.field;
            let newWidth = e.newWidth;
            if (newWidth < 20) {
                columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
            } else {
                columnResizeEvent($('body').data('menu_id'), field, newWidth, null, null, SUFFIX);
            }
        },
        columnReorder: function (e) {
            //  列拖动事件
            let newColumns = JSON.parse(JSON.stringify(e.sender.columns))
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);
            let menuId = $('body').data('menu_id');
            let col = []
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        serialNum: i,
                        sysMenuId: menuId,
                        field: newColumns[i]['field'] + SUFFIX
                    });
            }
            $.ajax({
                url: 'sysUserTableConfig/modify/reorder',
                contentType: 'application/json',
                data: JSON.stringify(col),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                }
            })
        },
    });
    let grid01 = $('#v_grid_6').data('kendoGrid');
    loadOptions(grid01, columns, SUFFIX, $('body').data('menu_id'));
    grid01.setOptions({
        columns: columns
    });
    grid.on('dblclick', 'tr', function (e) {
        //  修改单据
        let kGrid = $("#v_grid_6").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        $('#ck_detail').dialog('open');
        getckdetail(0,dataItem.b_barcode)


    });
    grid.on('click', 'tr', function (e) {
        let kGrid = $("#v_grid_6").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        if (dataItem['is_audit']) {
            $('#btn_cancel_audit').linkbutton('enable')
        } else {
            $('#btn_cancel_audit').linkbutton('disable')
        }
    });
    grid.on('contextmenu', 'tr', function (e) {
        e.preventDefault();
        let kGrid = $('#v_grid_6').data('kendoGrid');
        var selectedRows = kGrid.select();
        let div = $(`<div class="easyui-menu">
                         <div data-options="name:'生成预发货码单',iconCls:'icon-ok'">生成预发货码单</div>
                         <div data-options="name:'转外厂',iconCls:'icon-ok'">库存退回</div>
                     </div>`);
        $('body').append(div);
        div.menu({
            onClick: function (item) {
                let name = item.text;
                switch (name) {
                    case '生成预发货码单':
                        let selectedDataItems = [];
                        let yfh_data=[];
                        for (let i = 0; i < selectedRows.length; i++) {
                            let dataItem = kGrid.dataItem(selectedRows[i]);
                            selectedDataItems.push(dataItem.b_barcode);
                            $('#client').combobox('setValue', dataItem.company_name);
                            let Obj= {
                                "product_name":dataItem.product_name,
                                "order_code":dataItem.order_code,
                                "material_specification":dataItem.material_specification,
                                "color":dataItem.color,
                                "ps":dataItem.ps,"qty":dataItem.qty,
                                "b_barcode":dataItem.b_barcode
                            };
                            yfh_data.push(Obj);
                        }
                        console.log(selectedDataItems);
                        if(yfh_data.length>0){
                            $('#client').combobox('readonly', false);
                            $('#yfh_win').dialog('open');
                            $("#hideClientA").checkbox('check').checked;
                            $("#address").combobox('disable');
                            $('#yfh_dg').datagrid('clearSelections');
                            $('#yfh_dg').datagrid('loadData', yfh_data);
                        }else{
                            $.messager.alert({title: '提示', msg: "未选择数据！！！"});
                        }
                        break;
                    case '库存退回':
                        $.messager.confirm('确认', '确定退回库存吗？', function (r) {
                            if (r) {
                                let rowdata = [];
                                for (let i = 0; i < selectedRows.length; i++) {
                                    let dataItem = kGrid.dataItem(selectedRows[i]);
                                    let Obj= {
                                        "bBarcode":dataItem.b_barcode,
                                        "convertBc":0,
                                        "bDTRK":dataItem.B_DTRK
                                    };
                                    rowdata.push(Obj);
                                }
                                $.ajax({
                                    url: 'gjrkbillCp/updateByConvertBc',
                                    contentType: 'application/json',
                                    data: JSON.stringify(rowdata),
                                    type: 'post',
                                    dataType: 'json',
                                    success: function (data) {
                                        console.log(data);
                                        btn_search();
                                    }
                                });
                            }
                        });
                }
            },
        });
        div.menu('show', {
            left: e.pageX,
            top: e.pageY
        })
    });
}

/**
 * 2025-5-22 09:55:58
 * 成品管理 - 第5个标签页 - 预发货细码单 明细
 */
function grid_4() {
    let SUFFIX = "_4e";
    let billcode = new kendo.data.DataSource({data: []});
    let datafh = new kendo.data.DataSource({data: []});
    let product_name = new kendo.data.DataSource({data: []});
    let specification = new kendo.data.DataSource({data: []});
    let color = new kendo.data.DataSource({data: []});
    let color_no = new kendo.data.DataSource({data: []});
    let memo = new kendo.data.DataSource({data: []});
    let address = new kendo.data.DataSource({data: []});
    let client = new kendo.data.DataSource({data: []});
    let alias = new kendo.data.DataSource({data: []});
    let company_name = new kendo.data.DataSource({data: []});
    let order_code = new kendo.data.DataSource({data: []});
    let remark = new kendo.data.DataSource({data: []});
    let B_BCFC = new kendo.data.DataSource({data: []});
    let B_JTH = new kendo.data.DataSource({data: []});

    let dataSource = new kendo.data.DataSource({
        schema: {
            model: {
                fields: {
                    ps: {type: "number"},
                    qty: {type: "number"},
                    // price: {type: "number"},
                    // money: {type: "number"},
                }
            }
        },
        aggregate: [
            {field: "ps", aggregate: "sum"},
            {field: "qty", aggregate: "sum"},
            // {field: "money", aggregate: "sum"},
        ],
        change: function (e) {
            // let data = this.data();
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            let data = query.filter(filtrer).data;

            client.data(unique(data, 'client'));
            billcode.data(unique(data, 'billcode'));
            product_name.data(unique(data, 'product_name'));
            specification.data(unique(data, 'specification'));
            color.data(unique(data, 'color'));
            color_no.data(unique(data, 'color_no'));
            memo.data(unique(data, 'memo'));
            alias.data(unique(data, 'alias'));
            address.data(unique(data, 'carnumber'));
            company_name.data(unique(data, 'company_name'));
            order_code.data(unique(data, 'order_code'));
            remark.data(unique(data, 'remark'));
            B_BCFC.data(unique(data, 'B_BCFC'));
            B_JTH.data(unique(data, 'B_JTH'));

        },
        pageSize: 200,
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('disable')
                }
            })
        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('enable')
                }
            })
        }
    });
    let columns = [
        {field: "no", title: "#", filterable: false, template: "<span class='row_number'></span>", width: 40},
        {
            field: "id",
            title: '编号',
            width: 93,
            hidden: true,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
        },
        {
            field: "client",
            title: '码单客户',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        },
        {
            field: "billcode",
            title: '细码单号',
            width: 93,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: billcode}
        },
        {
            field: "datafh",
            title: '扫码日期',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: datafh}
        },
        {
            field: "order_code",
            title: '订单号',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: order_code}
        },
        {
            field: "alias",
            title: '客户单号',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: alias}
        },
        {
            field: "company_name",
            title: '计划客户',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: company_name}
        },
        {
            field: "product_name",
            title: '品名',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: product_name}
        },
        {
            field: "specification",
            title: '规格',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: specification}
        },
        {
            field: "color",
            title: '颜色',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color}
        },
        {
            field: "B_BCFC",
            title: '卡片号',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: B_BCFC}
        },
        {
            field: "B_JTH",
            title: '机台号',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: B_JTH}
        },
        {
            field: "ps",
            title: '匹数',
            width: 93,
            template: item => item['ps'] ? parseFloat(item['ps']).toFixed(0) : '',
            footerTemplate: '#=kendo.format("{0:n0}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "qty",
            title: '重量',
            width: 93,
            template: item => item['qty'] ? parseFloat(item['qty']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        // {
        //     field: "price",
        //     title: '单价',
        //     width: 93,
        //     template: item => item['price'] ? parseFloat(item['price']).toFixed(1) : '',
        //     // footerTemplate: '#=kendo.format("{0:n0}",sum)#',
        //     footerAttributes: {'style': 'text-align:right;'},
        //     attributes: {'class': 'kendo-custum-number'},
        //     headerAttributes: {'style': 'text-align:center;'},
        //     filterable: false
        // },
        // {
        //     field: "money",
        //     title: '金额',
        //     width: 93,
        //     template: item => item['money'] ? parseFloat(item['money']).toFixed(1) : '',
        //     footerTemplate: '#=kendo.format("{0:n1}",sum)#',
        //     footerAttributes: {'style': 'text-align:right;'},
        //     attributes: {'class': 'kendo-custum-number'},
        //     headerAttributes: {'style': 'text-align:center;'},
        //     filterable: false
        // },
        // {
        //     field: "manager",
        //     title: '经手人',
        //     width: 80,
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: manager}
        // },
        // {
        //     field: "carnumber",
        //     title: '车牌号',
        //     width: 80,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: carnumber}
        // },
        // {
        //     field: "address",
        //     title: '收货单位',
        //     width: 120,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: address}
        // },
        // {
        //     field: "hideClient",
        //     title: '打印客户',
        //     width: 100,
        //     template: item => item['hideClient'] ? '是' : '否',
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: false
        // },
        // {
        //     field: "showPrice",
        //     title: '打印单价',
        //     width: 100,
        //     template: item => item['showPrice'] ? '是' : '否',
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: false
        // },
        // {
        //     field: "memo",
        //     title: '发货备注',
        //     width: 150,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: memo}
        // },
        // {
        //     field: "remark",
        //     title: '厂内备注',
        //     width: 150,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: remark}
        // },


    ];
    let grid = $("#v_grid_4").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: {
            extra: false
        },
        dataSource: dataSource,
        columnMenu: false,
        excel: {
            fileName: "预发货单明细.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        height: '99%',
        pageable: {
            pageSize: 200
        },
        reorderable: true,
        dataBound: function () {
            let rows = this.items();
            let kGrid = $('#v_grid_4').data('kendoGrid');
            $(rows).each(function () {
                let index = $(this).index() + 1;
                let rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
                let dataItem = kGrid.dataItem($(this));
                if (dataItem['is_audit'] != undefined && !dataItem['is_audit']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
                if (dataItem['state'] != undefined && !dataItem['state']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
            });
        },
        columnHide: function (e) {
            //列隐藏事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
        },
        columnShow: function (e) {
            //列显示事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, false, null, SUFFIX);
        },
        columnResize: function (e) {
            //  列伸缩事件
            let field = e.column.field;
            let newWidth = e.newWidth;
            if (newWidth < 20) {
                columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
            } else {
                columnResizeEvent($('body').data('menu_id'), field, newWidth, null, null, SUFFIX);
            }
        },
        columnReorder: function (e) {
            //  列拖动事件
            let newColumns = JSON.parse(JSON.stringify(e.sender.columns))
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);
            let menuId = $('body').data('menu_id');
            let col = []
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        serialNum: i,
                        sysMenuId: menuId,
                        field: newColumns[i]['field'] + SUFFIX
                    });
            }
            $.ajax({
                url: 'sysUserTableConfig/modify/reorder',
                contentType: 'application/json',
                data: JSON.stringify(col),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                }
            })
        },
    });
    let grid01 = $('#v_grid_4').data('kendoGrid');
    loadOptions(grid01, columns, SUFFIX, $('body').data('menu_id'));
    grid01.setOptions({
        columns: columns
    });
    grid.on('dblclick', 'tr', function (e) {
        setgrid_fh();
        //  修改单据
        let kGrid = $("#v_grid_4").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        open_fhdetail(dataItem);
    })
    grid.on('click', 'tr', function (e) {
        // let kGrid = $("#v_grid_4").data("kendoGrid");
        // let dataItem = kGrid.dataItem(e.currentTarget);
        // if (dataItem['is_audit']) {
        //     $('#btn_cancel_audit').linkbutton('enable')
        // } else {
        //     $('#btn_cancel_audit').linkbutton('disable')
        // }
    })
}

/**
 * 2025-5-22 10:12:55
 * 成品管理 - 第6个标签页 - 发货单 明细
 */
function grid_5() {
    let SUFFIX = "_5f";
    let billcode = new kendo.data.DataSource({data: []});
    let client = new kendo.data.DataSource({data: []});
    let datafh = new kendo.data.DataSource({data: []});
    let memo = new kendo.data.DataSource({data: []});
    let address = new kendo.data.DataSource({data: []});
    let plan_code = new kendo.data.DataSource({data: []});
    let order_code = new kendo.data.DataSource({data: []});
    let alias = new kendo.data.DataSource({data: []});
    let product_name = new kendo.data.DataSource({data: []});
    let color_no = new kendo.data.DataSource({data: []});
    let color = new kendo.data.DataSource({data: []});
    let material_specification = new kendo.data.DataSource({data: []});
    let B_JTH = new kendo.data.DataSource({data: []});

    let dataSource = new kendo.data.DataSource({
        schema: {
            model: {
                fields: {
                    ps: {type: "number"},
                    qty: {type: "number"},
                    // price: {type: "number"},
                    // money: {type: "number"},
                }
            }
        },
        aggregate: [
            {field: "ps", aggregate: "sum"},
            {field: "qty", aggregate: "sum"},
            // {field: "money", aggregate: "sum"},
        ],
        change: function (e) {
            // let data = this.data();
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            let data = query.filter(filtrer).data;

            client.data(unique(data, 'client'));
            billcode.data(unique(data, 'billcode'));
            memo.data(unique(data, 'memo'));
            address.data(unique(data, 'address'));
            plan_code.data(unique(data, 'plan_code'));
            order_code.data(unique(data, 'order_code'));
            alias.data(unique(data, 'alias'));
            product_name.data(unique(data, 'product_name'));
            color_no.data(unique(data, 'color_no'));
            color.data(unique(data, 'color'));
            material_specification.data(unique(data, 'material_specification'));
            B_JTH.data(unique(data, 'B_JTH'));

        },
        pageSize: 200,
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('disable')
                }
            })
        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('enable')
                }
            })
        }
    });
    let columns = [
        {field: "no", title: "#", filterable: false, template: "<span class='row_number'></span>", width: 40},
        {
            field: "id",
            title: '编号',
            width: 93,
            hidden: true,
            attributes: {'style': 'white-space:nowrap;text-overflow:ellipsis;'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
        },
        {
            field: "billcode",
            title: '发货单号',
            width: 93,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: billcode}
        },
        {
            field: "datafh",
            title: '发货日期',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: datafh}
        },
        {
            field: "client",
            title: '客户',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: client}
        },
        {
            field: "order_code",
            title: '订单号',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: order_code}
        },
        {
            field: "alias",
            title: '客户单号',
            width: 85,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: alias}
        },
        {
            field: "product_name",
            title: '品名',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: product_name}
        },
        {
            field: "material_specification",
            title: '规格',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: material_specification}
        },
        {
            field: "color",
            title: '颜色',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: color}
        },
        {
            field: "plan_code",
            title: '卡片号',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: plan_code}
        },
        {
            field: "B_JTH",
            title: '机台号',
            width: 85,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: B_JTH}
        },
        {
            field: "ps",
            title: '总匹数',
            width: 93,
            template: item => item['ps'] ? parseFloat(item['ps']).toFixed(0) : '',
            footerTemplate: '#=kendo.format("{0:n0}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "qty",
            title: '总重量',
            width: 93,
            template: item => item['qty'] ? parseFloat(item['qty']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        // {
        //     field: "price",
        //     title: '单价',
        //     width: 93,
        //     template: item => item['price'] ? parseFloat(item['price']).toFixed(1) : '',
        //     // footerTemplate: '#=kendo.format("{0:n0}",sum)#',
        //     footerAttributes: {'style': 'text-align:right;'},
        //     attributes: {'class': 'kendo-custum-number'},
        //     headerAttributes: {'style': 'text-align:center;'},
        //     filterable: false
        // },
        // {
        //     field: "money",
        //     title: '总金额',
        //     width: 93,
        //     template: item => item['money'] ? parseFloat(item['money']).toFixed(2) : '',
        //     footerTemplate: '#=kendo.format("{0:n1}",sum)#',
        //     footerAttributes: {'style': 'text-align:right;'},
        //     attributes: {'class': 'kendo-custum-number'},
        //     headerAttributes: {'style': 'text-align:center;'},
        //     filterable: false
        // },
        {
            field: "manager",
            title: '经手人',
            width: 80,
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: manager}
        },
        {
            field: "carnumber",
            title: '车牌号',
            width: 80,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: carnumber}
        },
        {
            field: "address",
            title: '收货单位',
            width: 120,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: address}
        },
        // {
        //     field: "hideClient",
        //     title: '打印客户',
        //     width: 100,
        //     template: item => item['hideClient'] ? '是' : '否',
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: false
        // },
        // {
        //     field: "showPrice",
        //     title: '打印单价',
        //     width: 100,
        //     template: item => item['showPrice'] ? '是' : '否',
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: false
        // },
        {
            field: "memo",
            title: '发货备注',
            width: 150,
            // format: "{0: MM-dd HH:mm}",
            headerAttributes: {'style': 'text-align:center;'},
            attributes: {'class': 'kendo-custum-char'},
            filterable: {checkAll: true, multi: true, search: true, dataSource: memo}
        },
        // {
        //     field: "remark",
        //     title: '厂内备注',
        //     width: 150,
        //     // format: "{0: MM-dd HH:mm}",
        //     headerAttributes: {'style': 'text-align:center;'},
        //     attributes: {'class': 'kendo-custum-char'},
        //     filterable: {checkAll: true, multi: true, search: true, dataSource: remark}
        // },


    ];
    let grid = $("#v_grid_5").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: {
            extra: false
        },
        dataSource: dataSource,
        columnMenu: false,
        excel: {
            fileName: "成品发货明细.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        height: '99%',
        pageable: {
            pageSize: 200
        },
        reorderable: true,
        dataBound: function () {
            let rows = this.items();
            let kGrid = $('#v_grid_5').data('kendoGrid');
            $(rows).each(function () {
                let index = $(this).index() + 1;
                let rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
                let dataItem = kGrid.dataItem($(this));
                if (dataItem['is_audit'] != undefined && !dataItem['is_audit']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
                if (dataItem['state'] != undefined && !dataItem['state']) {
                    $(this).addClass('kendo-custum-non-checked');
                }
            });
        },
        columnHide: function (e) {
            //列隐藏事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
        },
        columnShow: function (e) {
            //列显示事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, false, null, SUFFIX);
        },
        columnResize: function (e) {
            //  列伸缩事件
            let field = e.column.field;
            let newWidth = e.newWidth;
            if (newWidth < 20) {
                columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
            } else {
                columnResizeEvent($('body').data('menu_id'), field, newWidth, null, null, SUFFIX);
            }
        },
        columnReorder: function (e) {
            //  列拖动事件
            let newColumns = JSON.parse(JSON.stringify(e.sender.columns))
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);
            let menuId = $('body').data('menu_id');
            let col = []
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        serialNum: i,
                        sysMenuId: menuId,
                        field: newColumns[i]['field'] + SUFFIX
                    });
            }
            $.ajax({
                url: 'sysUserTableConfig/modify/reorder',
                contentType: 'application/json',
                data: JSON.stringify(col),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                }
            })
        },
    });
    let grid01 = $('#v_grid_5').data('kendoGrid');
    loadOptions(grid01, columns, SUFFIX, $('body').data('menu_id'));
    grid01.setOptions({
        columns: columns
    });
    grid.on('dblclick', 'tr', function (e) {
        setgrid_fh();
        //  修改单据
        let kGrid = $("#v_grid_5").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        open_fhdetail(dataItem);
    })
    grid.on('click', 'tr', function (e) {
        // let kGrid = $("#v_grid_5").data("kendoGrid");
        // let dataItem = kGrid.dataItem(e.currentTarget);
        // if (dataItem['is_audit']) {
        //     $('#btn_cancel_audit').linkbutton('enable')
        // } else {
        //     $('#btn_cancel_audit').linkbutton('disable')
        // }
    })
}

// 格式化数值字段，保留一位小数
function formatNumber(value, row, index) {
    return parseFloat(value).toFixed(1);
}

function formatNumber2(value, row, index) {
    return value?parseFloat(value).toFixed(2):'';
}

//预发货网格
function setgrid() {
    let currentIndex = getCurrentIndex();
    let columns;
    if (currentIndex == 0) {
        columns = [[
            {field: 'id', title: '细码单主键', align: 'center',hidden:true},
            {field: 'billDate', title: '扫码日期', align: 'center',width:80},
            {field: 'productName', title: '品名', align: 'center',width:80},
            {field: 'specification', title: '规格', align: 'center',width:80},
            {field: 'ps', title: '匹数', align: 'center',width:65},
            {field: 'qty', title: '重量', align: 'center',width:65,formatter: formatNumber},
            // {field: 'meter', title: '米数', align: 'center',width:65,formatter: formatNumber},
            {field: 'price', title: '单价', align: 'center',width:65,formatter: formatNumber2},
            {field: 'money', title: '金额', align: 'center',width:65,formatter: formatNumber2},
        ]]
    }else {
        columns = [[
            {field: 'product_name', title: '品名', align: 'center',width:80},
            {field: 'order_code', title: '订单号', align: 'center',width:80},
            {field: 'material_specification', title: '规格', align: 'center',width:80},
            {field: 'color', title: '颜色', align: 'center',width:50},
            {field: 'ps', title: '匹数', align: 'center',width:65},
            {field: 'qty', title: '重量', align: 'center',width:65,formatter: formatNumber},
            // {field: 'meter', title: '米数', align: 'center',width:65,formatter: formatNumber},
            {field: 'price', title: '单价', align: 'center',width:65,hidden:true},
            {field: 'money', title: '金额', align: 'center',width:65,hidden:true},
            {field: 'b_barcode', title: '货架号', align: 'center'}
        ]]
    }
    $('#yfh_dg').datagrid({
        data: [],
        striped: true,
        autoSave: false,
        sortable: true,
        fit:true,
        fitColumns:true,
        ctrlSelect:true,
        rownumbers:true,
        remoteSort: false,
        singleSelect: true,
        showFooter: true,
        idField: 'id',
        // height: 850,
        // width: 50,
        columns:columns,
        // onDblClickRow: function (Index,row) {//鼠标双击事件
        //     m_gridId=row.iid;
        //     open_win_grid(m_gridId);
        // }
        onLoadSuccess: function (data) {
            compute();
            $(this).datagrid('resize');
            console.log('onLoadSuccess')
        },
        onAfterDeleteRow: function(index, data){
            // 在删除行后触发的事件，你可以在这里进行相关操作
            compute();
            console.log('onAfterDeleteRow')
        },
        onRowContextMenu: function(e, index, row){
            e.preventDefault(); // 阻止默认右键菜单
            $('#yfh_dg').datagrid('selectRow', index); // 选中右键点击的行
            let div = $(`<div class="easyui-menu_yfh">
                         <div data-options="name:'生成发货',iconCls:'icon-cancel'">删除</div>
                     </div>`);
            $('body').append(div);
            div.menu({
                onClick: function (item) {
                    let name = item.text;
                    switch (name) {
                        case '删除':
                            console.log(index);
                            $('#yfh_dg').datagrid('deleteRow',index);
                            compute();
                            break;
                    }
                },
            });
            div.menu('show', {
                left: e.pageX,
                top: e.pageY
            })
        }
    });
}

//已发货明细网格
function setgrid_xmd() {
    $('#fh_dg').datagrid({
        striped: true, autoSave: false, sortable: true, fit:true, fitColumns:true, ctrlSelect:true, rownumbers:true, remoteSort: false, singleSelect: true, showFooter: true,
        columns:[[
            {field: 'B_ItemID', title: '打卷主键', align: 'center',hidden:true},
            {field: 'ph', title: '匹号', align: 'center'},
            {field: 'qty', title: '重量', align: 'center',width:80,formatter: formatNumber},
            {field: 'B_BCFC', title: '卡片号', align: 'center'},
            {field: 'qrcode', title: '二维码号', align: 'center'},
            {field: 'bDate', title: '打卷时间', align: 'center'},
            // {field: 'b_barcode', title: '货架号', align: 'center'},
        ]],
        // onDblClickRow: function (Index,row) {//鼠标双击事件
        //     m_gridId=row.iid;
        //     open_win_grid(m_gridId);
        // }
        onLoadSuccess: function (data) {
            compute_fh()
            $(this).datagrid('resize');
        },
        onAfterDeleteRow: function(index, data){
            // 在删除行后触发的事件，你可以在这里进行相关操作
        },
        onRowContextMenu: function(e, index, row){
            e.preventDefault(); // 阻止默认右键菜单
            $('#ck_dg').datagrid('selectRow', index); // 选中右键点击的行
            let div = $(`<div class="easyui-menu_fh">
                         <div data-options="name:'删除',iconCls:'icon-cancel'">删除</div>
                     </div>`);
            $('body').append(div);
            div.menu({
                onClick: function (item) {
                    let name = item.text;
                    switch (name) {
                        case '删除':
                            $.messager.confirm('确认', '确定删除当前选中数量吗？不可恢复', function (r) {
                                if (r) {
                                    console.log(row);
                                    $.ajax({
                                        url: "gjrkbillCp/clearFPDIDOne",
                                        type: 'post',
                                        data: JSON.stringify({"jrkId":row.B_ItemID}),
                                        contentType: "application/json;charset=UTF-8",
                                        success: function (cdata) {
                                            console.log(cdata);
                                            if (cdata.code===1){
                                                $('#fh_dg').datagrid('deleteRow',index);
                                                btn_search();
                                                compute_fh();
                                                $.messager.show({title: '提示', msg: "删除发货明细成功！"})
                                            }
                                        }
                                    });
                                }
                            })
                            break;
                    }
                },
            });
            div.menu('show', {
                left: e.pageX,
                top: e.pageY
            })
        }
    });
}

//已发货明细网格
function setgrid_fh() {
    $('#fh_dg_bill').datagrid({
        striped: true, autoSave: false, sortable: true, fit:true, fitColumns:true, ctrlSelect:true, rownumbers:true, remoteSort: false, singleSelect: false, showFooter: true,
        columns:[[
            {field: 'id', title: '细码单主键', align: 'center',hidden:true},
            {field: 'billDate', title: '扫码日期', align: 'center',width:80},
            {field: 'productName', title: '品名', align: 'center',width:80},
            {field: 'specification', title: '规格', align: 'center',width:80},
            {field: 'ps', title: '匹数', align: 'center',width:65},
            {field: 'qty', title: '重量', align: 'center',width:65,formatter: formatNumber},
            {field: 'price', title: '单价', align: 'center',width:65,formatter: formatNumber2},
            {field: 'money', title: '金额', align: 'center',width:65,formatter: formatNumber2},
            {field: 'checked', checkbox: true}
            // {field: 'remark', title: '厂内备注', align: 'center'},
            // {field: 'memo', title: '发货备注', align: 'center'}
        ]],
        onDblClickRow: function (Index,row) {//鼠标双击事件
            if (row.id) {
                $('#fh_barcode').textbox('setValue',row.billcode);
                $('#client_detail').combobox('setValue',row.client);
                if (row.hideClient){$("#hideClientC").checkbox('check').checked;}else{$("#hideClientC").checkbox('clear').checked;}
                $('#fh_detail').dialog('open');
                $.ajax({
                    url: "customize/callProc",
                    type: 'post',
                    data: JSON.stringify(['usp_getcpjrkdetail',row.id,0]),
                    contentType: "application/json;charset=UTF-8",
                    success: function (item) {
                        let  data=item.data;
                        if (Number(row.id)>0){
                            $('#fh_dg').datagrid('clearSelections');
                            $('#fh_dg').datagrid('loadData', data);
                        }else{
                            $('#ck_dg').datagrid('clearSelections');
                            $('#ck_dg').datagrid('loadData', data);
                        }
                    }, complete: function () {
                        $.messager.progress('close');
                    }
                })
            }
            // $.ajax({
            //     url: "cpBillfh/listQuery",
            //     type: 'GET',
            //     data: {mainId: row.id},
            //     success: function (cdata) {
            //     }, complete: function () {
            //         $.messager.progress('close');
            //     }
            // })
        },
        onLoadSuccess: function (data) {
            compute_bill();
            $(this).datagrid('resize');
        },
        onAfterDeleteRow: function(index, data){
            // 在删除行后触发的事件，你可以在这里进行相关操作
        },
        onRowContextMenu: function(e, index, row){
            e.preventDefault(); // 阻止默认右键菜单
            $('#ck_dg').datagrid('selectRow', index); // 选中右键点击的行
            let div = $(`<div class="easyui-menu_fh">
                         <div data-options="name:'删除',iconCls:'icon-cancel'">删除</div>
                     </div>`);
            $('body').append(div);
            div.menu({
                onClick: function (item) {
                    let name = item.text;
                    switch (name) {
                        case '删除':
                            $.messager.confirm('确认', '确定删除当前选中数量吗？不可恢复', function (r) {
                                if (r) {
                                    console.log(row);
                                    $.ajax({
                                        url: "cpBillfh/updatefh",
                                        type: 'post',
                                        data: JSON.stringify({"id":row.id}),
                                        contentType: "application/json;charset=UTF-8",
                                        success: function (cdata) {
                                            console.log(cdata);
                                            if (cdata.code===1){
                                                $('#fh_dg_bill').datagrid('deleteRow',index);
                                                btn_search();
                                                compute_fh();
                                                $.messager.show({title: '提示', msg: "删除细码单成功！"})
                                            }
                                        }
                                    });
                                }
                            })
                            break;
                    }
                },
            });
            div.menu('show', {
                left: e.pageX,
                top: e.pageY
            })
        }
    });
}

//库存明细网格
function setgrid_ck() {
    $('#ck_dg').datagrid({
        striped: true, autoSave: false, sortable: true, fit:true, fitColumns:true, ctrlSelect:true, rownumbers:true, remoteSort: false, singleSelect: true, showFooter: true,
        columns:[[
            {field: 'B_ItemID', title: '打卷主键', align: 'center',hidden:true},
            {field: 'ph', title: '匹号', align: 'center'},
            {field: 'qty', title: '重量', align: 'center',width:80,formatter: formatNumber},
            {field: 'meter', title: '米数', align: 'center',width:80,formatter: formatNumber},
            {field: 'B_BCFC', title: '卡片号', align: 'center'},
            {field: 'qrcode', title: '二维码号', align: 'center'},
            {field: 'bDate', title: '打卷时间', align: 'center'},
        ]],
        // onDblClickRow: function (Index,row) {//鼠标双击事件
        //     m_gridId=row.iid;
        //     open_win_grid(m_gridId);
        // }
        onLoadSuccess: function (data) {
            compute_ck();
            $(this).datagrid('resize');
        },
        onRowContextMenu: function(e, index, row){
            e.preventDefault(); // 阻止默认右键菜单
            $('#ck_dg').datagrid('selectRow', index); // 选中右键点击的行
            let div = $(`<div class="easyui-menu_ck">
                         <div data-options="name:'删除',iconCls:'icon-cancel'">删除</div>
                     </div>`);
            $('body').append(div);
            div.menu({
                onClick: function (item) {
                    let name = item.text;
                    switch (name) {
                        case '删除':
                            $.messager.confirm('确认', '确定删除当前选中数量吗？不可恢复', function (r) {
                                if (r) {
                                    console.log(row);
                                    $.ajax({
                                        url: "gjrkbillCp/delete/"+row.B_ItemID,
                                        type: 'post',
                                        dataType: 'json',
                                        contentType: "application/json;charset=UTF-8",
                                        success: function (cdata) {
                                            console.log(cdata);
                                            if (cdata.code===1){
                                                $('#ck_dg').datagrid('deleteRow',index);
                                                btn_search();
                                                compute_ck();
                                                $.messager.show({title: '提示', msg: "删除库存明细成功！"})
                                            }
                                        }
                                    });
                                }
                            })
                            break;
                    }
                },
            });
            div.menu('show', {
                left: e.pageX,
                top: e.pageY
            })
        }
    });
}
//合计
function compute() {
    let rows = $('#yfh_dg').datagrid("getRows");
    let ps = 0, qty = 0,money = 0;
    for (let i = 0; i < rows.length; i++) {
        ps += parseFloat(rows[i].ps ? rows[i].ps : 0);
        qty += parseFloat(rows[i].qty ? rows[i].qty : 0);
        money += parseFloat(rows[i].money ? rows[i].money : 0);
    }
    $('#yfh_dg').datagrid('reloadFooter', [
        {
            // product_name: '合计',
            ps: ps,
            qty: qty.toFixed(1),
            money:money
        }
    ]);
}

function compute_bill() {
    let rows = $("#fh_dg_bill").datagrid("getRows");
    let ps = 0, qty = 0, money = 0;
    for (let i = 0; i < rows.length; i++) {
        ps += parseFloat(rows[i].ps ? rows[i].ps : 0);
        qty += parseFloat(rows[i].qty ? rows[i].qty : 0);
        money += parseFloat(rows[i].money ? rows[i].money : 0);
    }
    $("#fh_dg_bill").datagrid('reloadFooter', [{ps: ps, qty: qty.toFixed(1),money: money.toFixed(2)}]);
}

function compute_fh() {
    let rows = $("#fh_dg").datagrid("getRows");
    let ps = 0, qty = 0;
    for (let i = 0; i < rows.length; i++) {
        ps += 1;
        qty += parseFloat(rows[i].qty ? rows[i].qty : 0);
    }
    $("#fh_dg").datagrid('reloadFooter', [{ph: ps, qty: qty.toFixed(1)}]);
}

function compute_ck() {
    let rows = $("#ck_dg").datagrid("getRows");
    let ps = 0, qty = 0;
    for (let i = 0; i < rows.length; i++) {
        ps += 1;
        qty += parseFloat(rows[i].qty ? rows[i].qty : 0);
    }
    $("#ck_dg").datagrid('reloadFooter', [{ph: ps, qty: qty.toFixed(1)}]);
}


/**
 * 2025年9月4日16:04:25 LINYUN 从日产量表中搬过来的报表
 * 成品管理 - 第四个标签页 - 待处理
 */
function grid_dcl() {
    let SUFFIX = "_dcl";
    let plan_code = new kendo.data.DataSource({data: []});
    let order_code = new kendo.data.DataSource({data: []});
    let client_code = new kendo.data.DataSource({data: []});
    let product_name = new kendo.data.DataSource({data: []});
    let menfu = new kendo.data.DataSource({data: []});
    let color = new kendo.data.DataSource({data: []});
    let company_name = new kendo.data.DataSource({data: []});
    let B_CiPinReason = new kendo.data.DataSource({data: []});
    let B_JTH = new kendo.data.DataSource({data: []});

    let dataSource = new kendo.data.DataSource({
        schema: {
            model: {
                fields: {
                    ps: {type: "number"},
                    qty: {type: "number"},
                    meter: {type: "number"},
                }
            }
        },
        aggregate: [
            {field: "ps", aggregate: "sum"},
            {field: "qty", aggregate: "sum"},
            {field: "meter", aggregate: "sum"},
        ],
        change: function (e) {
            // let data = this.data();
            //获取过滤条件
            let filtrer = this.filter();
            //获取所有数据
            let allData = this.data();
            //进行过滤条件的筛选
            let query = new kendo.data.Query(allData);
            //获取过过滤后的数据
            let data = query.filter(filtrer).data;

            plan_code.data(unique(data, 'plan_code'));
            order_code.data(unique(data, 'order_code'));
            client_code.data(unique(data, 'client_code'));
            product_name.data(unique(data, 'product_name'));
            menfu.data(unique(data, 'menfu'));
            color.data(unique(data, 'color'));
            B_CiPinReason.data(unique(data, 'B_CiPinReason'));
            B_JTH.data(unique(data, 'B_JTH'));

        },
        // pageSize: 200,
        requestStart: function (e) {
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('disable')
                }
            })
        },
        requestEnd: function (e) {
            let response = e.response;
            if (response && response['message']) {
                $.messager.show({title: '提示', msg: response['message']})
            }
            $('.easyui-linkbutton').each(function (index, item) {
                let btn = $(item);
                if (btn.linkbutton('options').text === '查询' || (btn.linkbutton('options').text === '过滤')) {
                    btn.linkbutton('enable')
                }
            })
        }
    });
    let columns = [
        {field: "no", title: "#", filterable: false, template: "<span class='row_number'></span>", width: 35},
        // {
        //     field: "company_name",
        //     title: '客户',
        //     width: 110,
        //     attributes: {'class': 'kendo-custum-char'},
        //     headerAttributes: {'style': 'text-align:center;'},
        //     footerAttributes: {'style': 'color: red;text-align:center;'},
        //     filterable: false
        //     // filterable: {checkAll: true, multi: true, search: true, dataSource: B_Date}
        // },
        {
            field: "plan_code",
            title: '机台卡片',
            width: 80,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: plan_code}
        },
        {
            field: "order_code",
            title: '订单号',
            width: 90,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: order_code}
        },
        {
            field: "client_code",
            title: '客户单号',
            width: 110,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: client_code}
        },
        {
            field: "product_name",
            title: '品名',
            width: 110,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: product_name}
        },
        {
            field: "menfu",
            title: '规格',
            width: 110,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: menfu}
        },
        {
            field: "color",
            title: '颜色',
            width: 80,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: color}
        },
        {
            field: "B_JTH",
            title: '机台号',
            width: 70,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: B_JTH}
        },
        {
            field: "ps",
            title: '匹数',
            width: 60,
            template: item => item['ps'] ? parseFloat(item['ps']).toFixed(0) : '',
            footerTemplate: '#=kendo.format("{0:n0}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "qty",
            title: '重量',
            width: 90,
            template: item => item['qty'] ? parseFloat(item['qty']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "meter",
            title: '米数',
            width: 90,
            template: item => item['meter'] ? parseFloat(item['meter']).toFixed(1) : '',
            footerTemplate: '#=kendo.format("{0:n1}",sum)#',
            footerAttributes: {'style': 'text-align:right;'},
            attributes: {'class': 'kendo-custum-number'},
            headerAttributes: {'style': 'text-align:center;'},
            filterable: false
        },
        {
            field: "B_CiPinReason",
            title: '待处理原因',
            width: 110,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            // filterable: false
            filterable: {checkAll: true, multi: true, search: true, dataSource: B_CiPinReason}
        },
        {
            field: "B_Date",
            title: '打卷时间',
            width: 150,
            attributes: {'class': 'kendo-custum-char'},
            headerAttributes: {'style': 'text-align:center;'},
            footerAttributes: {'style': 'color: red;text-align:center;'},
            filterable: false
            // filterable: {checkAll: true, multi: true, search: true, dataSource: B_JTH}
        },
        {
            field: "memo",
            title: ' ',
            width: 50,
            filterable: false
        },
    ];
    let grid = $("#v_grid_3").kendoGrid({
        sortable: true,
        resizable: true,
        selectable: "multiple row",
        editable: false,
        filterable: {
            extra: false
        },
        dataSource: dataSource,
        // columns:columns,
        columnMenu: false,
        excel: {
            fileName: "待处理明细.xlsx",
            proxyURL: "",
            allPages: true,
            filterable: true
        },
        height: '99%',
        // pageable: {
        //     pageSize: 200
        // },
        reorderable: true,
        dataBound: function () {
            let rows = this.items();
            let kGrid = $('#v_grid_3').data('kendoGrid');
            $(rows).each(function () {
                let index = $(this).index() + 1;
                let rowLabel = $(this).find(".row_number");
                $(rowLabel).html(index);
                let dataItem = kGrid.dataItem($(this));

            });
        },
        columnHide: function (e) {
            //列隐藏事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
        },
        columnShow: function (e) {
            //列显示事件
            let field = e.column.field;
            columnResizeEvent($('body').data('menu_id'), field, null, false, null, SUFFIX);
        },
        columnResize: function (e) {
            //  列伸缩事件
            let field = e.column.field;
            let newWidth = e.newWidth;
            if (newWidth < 20) {
                columnResizeEvent($('body').data('menu_id'), field, null, true, null, SUFFIX);
            } else {
                columnResizeEvent($('body').data('menu_id'), field, newWidth, null, null, SUFFIX);
            }
        },
        columnReorder: function (e) {
            //  列拖动事件
            let newColumns = JSON.parse(JSON.stringify(e.sender.columns))
            newColumns = reorder(newColumns, e.oldIndex, e.newIndex);
            let menuId = $('body').data('menu_id');
            let col = []
            for (let i = 0; i < newColumns.length; i++) {
                if (newColumns[i]['field'])
                    col.push({
                        serialNum: i,
                        sysMenuId: menuId,
                        field: newColumns[i]['field'] + SUFFIX
                    });
            }
            $.ajax({
                url: 'sysUserTableConfig/modify/reorder',
                contentType: 'application/json',
                data: JSON.stringify(col),
                type: 'post',
                dataType: 'json',
                success: function (data) {
                }
            })
        },
    });
    let grid01 = $('#v_grid_3').data('kendoGrid');
    loadOptions(grid01, columns, SUFFIX, $('body').data('menu_id'));
    grid01.setOptions({
        columns: columns
    });
    grid.on('dblclick', 'tr', function (e) {
        // setgrid_fh();
        // //  修改单据
        // let kGrid = $("#v_grid_3").data("kendoGrid");
        // let dataItem = kGrid.dataItem(e.currentTarget);
        // open_fhdetail(dataItem);
    })
    grid.on('click', 'tr', function (e) {
        let kGrid = $("#v_grid_3").data("kendoGrid");
        let dataItem = kGrid.dataItem(e.currentTarget);
        // console.log(dataItem);
        // if (dataItem['is_audit']) {
        //     $('#btn_cancel_audit').linkbutton('enable')
        // } else {
        //     $('#btn_cancel_audit').linkbutton('disable')
        // }
    })
    //右击事件
    grid.on('contextmenu', 'tr', function (e) {
        e.preventDefault();
        let kGrid = $("#v_grid_3").data("kendoGrid");
        kGrid.clearSelection();
        kGrid.select(this);
        let row = kGrid.select();
        let dataItem = kGrid.dataItem(row);
        let div = "<div id = 'mx_gridmenu_dcl'>"
            + "<div data-options=\"iconCls:'icon-edit'\">转正品</div>"
            + "</div>";
        if ($('#mx_gridmenu_dcl').length <= 0)
            $('body').append(div);
        $('#mx_gridmenu_dcl').menu({
            onClick: function (item) {
                let name = item.text;
                switch (name) {
                    case '转正品':
                        $.ajax({
                            url: 'gjrkbillCp/updateEDPById',
                            contentType: 'application/json',
                            data: JSON.stringify(dataItem.B_ItemID),
                            type: 'post',
                            dataType: 'json',
                            success: function (data) {
                                console.log(data);
                                btn_search()
                                $.messager.show({title: '提示', msg: '成功'});
                            }
                        })
                        break;
                }
            }
        });
        $('#mx_gridmenu_dcl').menu('show', {
            left: e.pageX,
            top: e.pageY
        });
    });
}

/************************************************************
 */
//预发货设置
function close_yfh() {
    $('#yfh_win').dialog('close');

    $('#client').combobox('setValue',"");
    $('#manager').textbox('setValue',"");
    $('#carnumber').textbox('setValue',"");
    $('#memo').textbox('setValue',"");
    $('#address').textbox('setValue',"");
    $('#price').textbox('setValue',"");

    $("#hideClientA").checkbox('check').checked;
    $("#showPriceA").checkbox('clear').checked;
}

function save_yfh() {
    let index = getCurrentIndex();
    var client = $('#client').combobox('getValue');
    var billdate = $('#billdate').datebox('getValue');
    // var manager = $('#manager').textbox('getValue');
    // var carnumber = $('#carnumber').textbox('getValue');
    var address= $('#address').textbox('getValue');
    // var memo = $('#memo').textbox('getValue');
    // var remark = $('#remark').textbox('getValue');
    // var price = $('#price').textbox('getValue');
    var hideClient=$("#hideClientA").checkbox('options').checked==true?1:0;
    // var showPrice=$("#showPriceA").checkbox('options').checked==true?1:0;

    // 获取datagrid中的所有数据
    var allData = $('#yfh_dg').datagrid('getData');
    if (allData.rows.length>0){}else{$.messager.alert({title: '提示', msg: "库存为空！"});return;}
    if (client.length>0){}else{$.messager.alert({title: '提示', msg: "客户不允许为空！"});return;}

    let shelveList=[];
    // let fhdObj={"client":client,"manager":manager,"carnumber":carnumber,"address":address,"memo":memo,"remark":remark,'hideClient':hideClient,'price':Number(price),'showPrice':showPrice};

    if (index == 0) {
        let fhdObj={"client":client,'hideClient':hideClient,'datafh':billdate,'address':address};
        for (let i=0;i<allData.rows.length;i++){
            shelveList.push(allData.rows[i])
        }
        let strData={"fhd":fhdObj,"list":shelveList};
        console.log(strData);
        $.ajax({
            url: "cpBillfhMain/insertToFH",
            type: 'post',
            data: JSON.stringify(strData),
            contentType: "application/json;charset=UTF-8",
            success: function (cdata) {
                if (cdata.id) {
                    close_fhdetail();
                    close_yfh();
                    btn_search();
                    $.messager.show({title: '提示', msg: "成功"});
                }else {
                    $.messager.show({title: '警告', msg: "所选细码单客户必须一致！！！"});
                }
            }
        })
    }
    if (index == 3 || index == 4) {
        let fhdObj={"client":client,'hideClient':hideClient};
        for (let i=0;i<allData.rows.length;i++){
            shelveList.push(allData.rows[i].b_barcode)
        }
        let strData={"fhd":fhdObj,"shelveList":shelveList};
        console.log(strData);
        $.ajax({
            url: "cpBillfh/insert8ShelvesListClient",
            type: 'POST',
            dataType: 'json',
            data: JSON.stringify(strData),
            // data:{"jrkId":50,"deviceId":223},
            contentType: "application/json;charset=UTF-8",
            success: function (cdata) {
                // let data=cdata.data;
                console.log(cdata);
                $.messager.show({title: '提示', msg: "生成细码单完成！！！"});
                close_yfh();
                close_fhdetail();
                // getgriddata(2);
                $('#tabs').tabs('select', 0);
            }
        });
    }
}

/************************************************************
 *
 */
//已生成发货单 设置抬头 批量修改
function save_main() {
    var client = $('#client_main').combobox('getValue');
    var manager = $('#manager_main').textbox('getValue');
    var carnumber = $('#carnumber_main').textbox('getValue');
    var address= $('#address_main').textbox('getValue');
    var memo = $('#memo_main').textbox('getValue');
    var remark = $('#remarkB').textbox('getValue');

    var hideClient=$("#hideClientB").checkbox('options').checked==true?1:0;

    var price = $('#priceB').textbox('getValue');
    var showPrice=$("#showPriceB").checkbox('options').checked==true?1:0;


    let strSQL=[];
    let kGrid = $('#v_grid').data('kendoGrid');
    var selectedRows = kGrid.select();
    for (let i = 0; i < selectedRows.length; i++) {
        let dataItem = kGrid.dataItem(selectedRows[i]);
        let Obj= {"id":dataItem.id,"client":client,"manager":manager, "carnumber":carnumber,"address":address,"memo":memo,"remark":remark,'hideClient':hideClient,'price':Number(price),'showPrice':showPrice};
        strSQL.push(Obj);
    }

    console.log(strSQL);

    $.ajax({
        url: "cpBillfh/multiUpdate",
        type: 'post',
        data: JSON.stringify(strSQL),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            // let  data=cdata.data;
            console.log('批量修改返回值：',cdata);
            close_main();
            btn_search();
        }
    });

}
function saveprint_main() {
    close_main()
}
function close_main() {
    $('#fh_main').dialog('close');

    $('#client_main').combobox('setValue',"");
    $('#manager_main').textbox('setValue',"");
    $('#carnumber_main').textbox('setValue',"");
    $('#memo_main').textbox('setValue',"");
    $('#remarkB').textbox('setValue',"");
    $('#address_main').textbox('setValue',"");
    $('#priceB').textbox('setValue',"");

    $("#hideClientB").checkbox('check').checked;
    $("#showPriceB").checkbox('clear').checked;
}
/************************************************************
 * */

function close_cpdetail() {
    $('#ck_detail').dialog('close');
    // btn_search()
}
/************************************************************
 * */

//关闭发货明细 窗口
function close_fhdetail() {
    $('#fh_detail').dialog('close');
    // btn_search()
}

function close_fhbill() {
    $('#fh_bill').dialog('close');
}

//打开发货明细 窗口
function open_fhdetail(dataItem) {
    let index = getCurrentIndex();
    if (index == 0) {
        $('#fh_barcode').textbox('setValue',dataItem.billcode);
        $('#client_detail').combobox('setValue',dataItem.client);
        // $('#manager_detail').textbox('setValue',dataItem.manager);
        // $('#carnumber_detail').textbox('setValue',dataItem.carnumber);
        // $('#memo_detail').textbox('setValue',dataItem.memo);
        // $('#remarkC').textbox('setValue',dataItem.remark);
        // $('#address_detail').textbox('setValue',dataItem.address);
        $('#priceC').textbox('setValue',dataItem.price);

        if (dataItem.hideClient){$("#hideClientC").checkbox('check').checked;}else{$("#hideClientC").checkbox('clear').checked;}
        // if (dataItem.showPrice){$("#showPriceC").checkbox('check').checked;}else{$("#showPriceC").checkbox('clear').checked;}

        $('#fh_detail').dialog('open');
    }
    if (index == 1) {
        $('#bill_barcode').textbox('setValue',dataItem.billcode);
        $('#bill_date').textbox('setValue',dataItem.datafh);
        $('#client_bill').combobox('setValue',dataItem.client);
        $('#manager_bill').textbox('setValue',dataItem.manager);
        $('#carnumber_bill').textbox('setValue',dataItem.carnumber);
        $('#memo_bill').textbox('setValue',dataItem.memo);
        $('#remark_bill').textbox('setValue',dataItem.remark);
        $('#address_bill').combobox('setValue',dataItem.address);
        // $('#priceC').textbox('setValue',dataItem.price);

        if (dataItem.hideClient){$("#hideClientC").checkbox('check').checked;}else{$("#hideClientC").checkbox('clear').checked;}
        // if (dataItem.showPrice){$("#showPriceC").checkbox('check').checked;}else{$("#showPriceC").checkbox('clear').checked;}

        $('#fh_bill').dialog('open');
    }
    getckdetail(dataItem.id,0, dataItem);
}
// 设置码单明细
function save_fhdetail() {
    let client = $('#client_detail').combobox('getValue');
    // var manager = $('#manager_detail').textbox('getValue');
    // var carnumber = $('#carnumber_detail').textbox('getValue');
    // var memo= $('#memo_detail').textbox('getValue');
    // var remark= $('#remarkC').textbox('getValue');

    // var address = $('#address_detail').textbox('getValue');

    // let hideClient=$("#hideClientC").checkbox('options').checked==true?1:0;

    let price = $('#priceC').textbox('getValue');
    // let showPrice=$("#showPriceC").checkbox('options').checked==true?1:0;
    let strSQL=[];
    let kGrid = $('#v_grid').data('kendoGrid');
    let selectedRows = kGrid.select();
    for (let i = 0; i < selectedRows.length; i++) {
        let dataItem = kGrid.dataItem(selectedRows[i]);

        // let Obj= {"id":dataItem.id,"client":client,"manager":manager, "carnumber":carnumber,"address":address,"memo":memo,'remark':remark,'hideClient':hideClient,'price':Number(price),'showPrice':showPrice};
        let Obj= {"id":dataItem.id,"client":client,'price':Number(price)};
        strSQL.push(Obj);
    }
    console.log(strSQL);
    $.ajax({
        url: "cpBillfh/multiUpdate",
        type: 'post',
        data: JSON.stringify(strSQL),
        contentType: "application/json;charset=UTF-8",
        success: function (cdata) {
            // let  data=cdata.data;
            console.log('修改明细返回值：',cdata);
            close_fhdetail();
            btn_search();
        }
    });
}

// 设置码单
function save_fhbill() {
    let index = getCurrentIndex();

    let client = $('#client_bill').combobox('getValue');
    let datafh = $('#bill_date').datebox('getValue');
    let manager = $('#manager_bill').textbox('getValue');
    let carnumber = $('#carnumber_bill').textbox('getValue');
    let memo= $('#memo_bill').textbox('getValue');
    // let remark= $('#remark_bill').textbox('getValue');

    let address = $('#address_bill').textbox('getValue');

    let hideClient=$("#hideClient_bill").checkbox('options').checked==true?1:0;

    // var price = $('#priceC').textbox('getValue');
    // var showPrice=$("#showPriceC").checkbox('options').checked==true?1:0;
    let strSQL=[];

    if (index == 1) {
        let kGrid = $('#v_grid_0').data('kendoGrid');
        let selectedRows = kGrid.select();
        for (let i = 0; i < selectedRows.length; i++) {
            let dataItem = kGrid.dataItem(selectedRows[i]);
            let Obj= {"id":dataItem.id,"client":client,"manager":manager, "carnumber":carnumber,"address":address,"memo":memo,'hideClient':hideClient,'datafh':datafh};
            strSQL.push(Obj);
        }
        console.log(strSQL);
        $.ajax({
            url: "cpBillfhMain/update",
            type: 'post',
            data: JSON.stringify(strSQL[0]),
            contentType: "application/json;charset=UTF-8",
            success: function (cdata) {
                // let  data=cdata.data;
                console.log('修改明细返回值：',cdata);
                close_fhbill();
                btn_search();
            }
        });
    }else {
        let kGrid = $('#v_grid_0').data('kendoGrid');
        let selectedRows = kGrid.select();
        for (let i = 0; i < selectedRows.length; i++) {
            let dataItem = kGrid.dataItem(selectedRows[i]);

            let Obj= {"id":dataItem.id,"client":client,"manager":manager, "carnumber":carnumber,"address":address,"memo":memo,'remark':remark,'hideClient':hideClient};
            strSQL.push(Obj);
        }
        console.log(strSQL);
        $.ajax({
            url: "cpBillfh/multiUpdate",
            type: 'post',
            data: JSON.stringify(strSQL),
            contentType: "application/json;charset=UTF-8",
            success: function (cdata) {
                // let  data=cdata.data;
                console.log('修改明细返回值：',cdata);
                close_fhbill();
                btn_search();
            }
        });
    }


}

/************************************************************
 * */

//打印发货单
function btn_print_bill() {
    let reportlets = [];
    $.get('customize/getDatabase', {}, data => {
        if (data.success) {
            switch (getCurrentIndex()) {
                case 0:
                    break;
                case 1:
                    let kGrid = $('#v_grid_0').data('kendoGrid');
                    var selectedRows = kGrid.select();
                    for (let i = 0; i < selectedRows.length; i++) {
                        let dataItem = kGrid.dataItem(selectedRows[i]);
                        let Obj= {
                            reportlet: `${data.data}/invoice-cpfh.cpt`,
                            id: dataItem.id,
                            database: data.data
                        };
                        reportlets.push(Obj);
                    }
                    console.log(reportlets);
                    window.parent.FR.doURLPDFPrint({
                        url: $(window.parent.document.body).data('report_url'),
                        isPopUp: false,
                        data: {
                            reportlets: reportlets
                        }
                    })
                    break;
                case 2:
                    break;
            }
        }
    }, 'json');
}

//库存明细获取数据
function getckdetail(m_FPDID,m_barcode, dataItem) {
    $.messager.progress({title: '', msg: '请稍等...', interval: 5000});
    let index = getCurrentIndex();
    if (index == 1) {
        $.ajax({
            url: "cpBillfh/listQuery",
            type: 'GET',
            data: {mainId: dataItem.id},
            success: function (cdata) {
                if (cdata.length) {
                    $('#fh_dg_bill').datagrid('clearSelections');
                    $('#fh_dg_bill').datagrid('loadData', cdata);
                }
            }, complete: function () {
                $.messager.progress('close');
            }
        })
    } else {
        $.ajax({
            url: "customize/callProc",
            type: 'post',
            data: JSON.stringify(['usp_getcpjrkdetail',m_FPDID,m_barcode]),
            contentType: "application/json;charset=UTF-8",
            success: function (cdata) {
                let  data=cdata.data;
                if (Number(m_FPDID)>0){
                    $('#fh_dg').datagrid('clearSelections');
                    $('#fh_dg').datagrid('loadData', data);
                }else{
                    $('#ck_dg').datagrid('clearSelections');
                    $('#ck_dg').datagrid('loadData', data);
                }
            }, complete: function () {
                $.messager.progress('close');
            }
        })
    }
}
//清除过滤
function btn_cancel_filter() {
    switch (getCurrentIndex()) {
        case 0:
            $('#v_grid').data('kendoGrid').dataSource.filter({});
            break;
        case 1:
            $('#v_grid_0').data('kendoGrid').dataSource.filter({});
            break;
        case 2:
            $('#v_grid_1').data('kendoGrid').dataSource.filter({});
            break;
        case 3:
            $('#v_grid_2').data('kendoGrid').dataSource.filter({});
            break;
        case 4:
            $('#v_grid_3').data('kendoGrid').dataSource.filter({});
            break;
        case 5:
            $('#v_grid_6').data('kendoGrid').dataSource.filter({});
            break;
        case 6:
            $('#v_grid_4').data('kendoGrid').dataSource.filter({});
            break;
        case 7:
            $('#v_grid_5').data('kendoGrid').dataSource.filter({});
            break;
    }
    // $('#v_grid').data('kendoGrid').dataSource.filter({});
}
//查询事件
function btn_search() {
    switch (getCurrentIndex()) {
        case 0:
            getgriddata(0);
            break;
        case 1:
            getgriddata(3);
            break;
        case 2:
            getgriddata(1);
            break;
        case 3:
            getgriddata(2);
            break;
        case 4:
            getgriddata(7);
            break;
        case 5:
            getgriddata(6);
            break;
        case 6:
            getgriddata(4);
            break;
        case 7:
            getgriddata(5);
            break;
    }
}

//生成发货单
function btn_add() {
    var grid = $("#v_grid").data("kendoGrid");
    var selectedDataItems = [];
    var Judge_client=true;
    // 遍历所有选中的行
    grid.select().each(function() {
        // 获取每行对应的数据项
        var dataItem = grid.dataItem(this);
        if (selectedDataItems.length > 0) {
            // if (selectedDataItems[0].company_name !== dataItem.company_name) {
            // company_name 计划客户

            if (selectedDataItems[0].client !== dataItem.client) {
                Judge_client=false;
                // $.messager.show({title: '警告', msg: "码单客户必须一致！！！"});
                // return;
            }
            // let Obj= {
            //     "product_name":dataItem.product_name,
            //     "order_code":dataItem.order_code,
            //     "material_specification":dataItem.material_specification,
            //     "color":dataItem.color,
            //     "ps":dataItem.ps,"qty":dataItem.qty,
            //     "b_barcode":dataItem.b_barcode
            // };
            dataItem.productName = dataItem.product_name;
            dataItem.client = dataItem.client;
            dataItem.billDate = dataItem.datafh;
            selectedDataItems.push(dataItem);
        }else {
            dataItem.productName = dataItem.product_name;
            dataItem.client = dataItem.client;
            dataItem.billDate = dataItem.datafh;
            selectedDataItems.push(dataItem);
        }
    });

    if (!Judge_client) {
        $.messager.show({title: '警告', msg: "码单客户必须一致！！！"});
        return;
    }

    console.log(selectedDataItems);
    $('#client').combobox('setValue', selectedDataItems[0].client);
    // 获取完整数据源
    var data = $('#client').combobox('getData');
    // 查找选中项的对象
    let selectedItem = null;
    for (var i = 0; i < data.length; i++) {
        if (data[i].companyName == selectedDataItems[0].client) {
            selectedItem = data[i];
            break;
        }
    }
    if (selectedItem) $('#address').textbox('setValue', selectedItem.address);
    $('#yfh_win').dialog('open');
    $("#hideClientA").checkbox('check').checked;
    $('#yfh_dg').datagrid('clearSelections');
    $('#yfh_dg').datagrid('loadData', selectedDataItems);
}

//删除发货单
function btn_delete() {
    var grid = $("#v_grid_0").data("kendoGrid");
    var selectedRows = grid.select(); // 获取所有选中的行（数组）
    var selectedData = [];
    selectedRows.each(function() {
        selectedData.push(grid.dataItem(this)); // 将每行数据存入数组
    });
    if (!selectedData.length) {
        $.messager.show({title: '提示', msg: "请先在表格选中一行"});
        return;
    }
    let cpBillfhMain = selectedData[0];
    $.messager.confirm('确认', '确定删除选中的发货单吗？不可恢复', function (r) {
        if (r) {
            $.ajax({
                url: "cpBillfhMain/deleteFhd/" + cpBillfhMain.id,
                type: 'post',
                contentType: "application/json;charset=UTF-8",
                success: function (cdata) {
                    // let  data=cdata.data;
                    console.log('修改明细返回值：',cdata);
                    close_fhdetail();
                    btn_search();
                }
            })
        }
    })
}

/********************************************
 */
//获取标签页序号
function getCurrentIndex() {
    let tab = $('#tabs').tabs('getSelected');
    let index = $('#tabs').tabs('getTabIndex', tab);
    return index;
}
//获取当前标签页的网格对象
function getSelectedGrid() {
    let kendoGridID = '';
    switch (getCurrentIndex()) {
        case 0:
            kendoGridID = '#v_grid';
            break;
        case 1:
            kendoGridID = '#v_grid_0';
            break;
        case 2:
            kendoGridID = '#v_grid_1';
            break;
        case 3:
            kendoGridID = '#v_grid_2';
            break;
        case 4:
            kendoGridID = '#v_grid_3';
            break;
        case 5:
            kendoGridID = '#v_grid_6';
            break;
        case 6:
            kendoGridID = '#v_grid_4';
            break;
        case 7:
            kendoGridID = '#v_grid_5';
            break;
    }
    return $(kendoGridID).data('kendoGrid');
}
//打印
function btn_print() {
    let reportlets = [];
    $.get('customize/getDatabase', {}, data => {
        if (data.success) {
            switch (getCurrentIndex()) {
                case 0:
                    let kGrid = $('#v_grid').data('kendoGrid');
                    var selectedRows = kGrid.select();
                    for (let i = 0; i < selectedRows.length; i++) {
                        let dataItem = kGrid.dataItem(selectedRows[i]);
                        if (dataItem.client){
                            let Obj= {
                                reportlet: `${data.data}/invoice-fhd.cpt`,
                                id: dataItem.id,
                                database: data.data
                            };
                            reportlets.push(Obj);
                        }else{
                            $.messager.alert({title: '提示', msg: "未设置客户，不允许打印！"});
                            return;
                        }

                    }
                    console.log(reportlets);
                    window.parent.FR.doURLPDFPrint({
                        url: $(window.parent.document.body).data('report_url'),
                        isPopUp: false,
                        data: {
                            reportlets: reportlets
                        }
                    })
                    break;
                case 1:
                    let datagrid = $('#fh_dg_bill').datagrid('getSelections');
                    if (!datagrid.length) {
                        $.messager.alert({title: '提示', msg: "请勾选行后再试！"});
                        return;
                    }
                    for (let i = 0; i < datagrid.length; i++) {
                        let dataItem = datagrid[i];
                        if (dataItem.client){
                            // let Obj= {
                            //     reportlet: `${data.data}/invoice-fhd.cpt`,
                            //     id: dataItem.id,
                            //     database: data.data
                            // };
                            // reportlets.push(Obj);
                        }else{
                            $.messager.alert({title: '提示', msg: "未设置客户，不允许打印！"});
                            return;
                        }
                    }
                    /** 2025-6-7 15:25:46 改
                     打印细码单按品名规格 汇总打印
                     下面方法是处理获取的数据，把相同品名规格的id拼接存储
                     */
                    const result = Object.values(
                        datagrid.reduce((acc, {id, productName, specification}) => {
                            const key = `${productName}|${specification}`;
                            acc[key] = acc[key] || {productName, specification, ids: []};
                            acc[key].ids.push(id);
                            return acc;
                        }, {})
                    ).map(({productName, specification, ids}) => ({
                        productName,
                        specification,
                        id: ids.join(',')
                    }));

                    for (let i = 0; i < result.length; i++) {
                        let dataItem = result[i];
                        let Obj= {
                            reportlet: `${data.data}/invoice-fhd.cpt`,
                            id: dataItem.id,
                            database: data.data
                        };
                        reportlets.push(Obj);
                    }
                    console.log(reportlets);
                    window.parent.FR.doURLPDFPrint({
                        url: $(window.parent.document.body).data('report_url'),
                        isPopUp: false,
                        data: {
                            reportlets: reportlets
                        }
                    })
                    break;
                case 2:
                    // reportlets.push({
                    //     reportlet: `${data.data}/色布库存序时表打印.cpt`,
                    //     Sdate: $('#start').datebox('getValue'),
                    //     Edate: $('#end').datebox('getValue'),
                    //     clientName: $('#contactCompanyId').combobox('getValue') || '',
                    //     database: data.data
                    // });
                    // window.parent.FR.doURLPDFPrint({
                    //     url: $(window.parent.document.body).data('report_url'),
                    //     isPopUp: false,
                    //     data: {
                    //         reportlets: reportlets
                    //     }
                    // })
                    break;
            }
        }
    }, 'json');
}

//z自动列设置
function btn_open_column_list() {
    let kGrid = getSelectedGrid();
    let options = kGrid.getOptions().columns;
    if ($('#btn_open_column_list').length <= 0) {
        let div = $(`<div data-options="
                    resizable:true,iconCls:'icon-filter',width:200,height:500,modal:true,title:'列',
                    onClose:function(){$(this).dialog('destroy')}" 
                          class="easyui-dialog" id="btn_open_column_list">
                   </div>`);
        let form = $('<form style="width: 100%;height: 100%;"></form>')
        for (let i of options) {
            if (i.field) {
                let checkbox = $(`<div style="width: 100%;height: auto;padding: 5px;">
                <input class="easyui-checkbox" name="${i.field}" data-options="label:'${i.title}',
                labelWidth:120,value:true,name:'${i.field}'">
                </div>`);
                form.append(checkbox);
            }
        }
        let container = $(`<div></div>`);
        form.appendTo(div);
        div.appendTo(container);
        $('body').append(container);
        $.parser.parse($('#btn_open_column_list').parent());
        let formData = {};
        options.map(item => {
            formData[item['field']] = item['hidden'] == undefined ? true : !item['hidden'];
        })
        $('#btn_open_column_list form').eq(0).form('load', formData);
        $('#btn_open_column_list form .easyui-checkbox').each(function () {
            //  绑定事件
            $(this).checkbox({
                onChange: function (checked) {
                    let opts = $(this).checkbox('options');
                    if (checked) {
                        kGrid.showColumn(opts.name);
                    } else {
                        kGrid.hideColumn(opts.name);
                    }
                }
            })
        })
    } else {
        $('#btn_open_column_list').dialog('open');
    }
}
//导出
function btn_export_excel() {
    switch (getCurrentIndex()) {
        case 0:
            $('#v_grid').data('kendoGrid').saveAsExcel();
            break;
        case 1:
            $('#v_grid_0').data('kendoGrid').saveAsExcel();
            break;
        case 2:
            $('#v_grid_1').data('kendoGrid').saveAsExcel();
            break;
        case 3:
            $('#v_grid_2').data('kendoGrid').saveAsExcel();
            break;
        case 4:
            $('#v_grid_3').data('kendoGrid').saveAsExcel();
            break;
        case 5:
            $('#v_grid_6').data('kendoGrid').saveAsExcel();
            break;
        case 6:
            $('#v_grid_4').data('kendoGrid').saveAsExcel();
            break;
        case 7:
            $('#v_grid_5').data('kendoGrid').saveAsExcel();
            break;
    }
}


function btn_close() {
    window.parent.closeTab();
}
